Index in position 1 is invalid. Array indices must be positive integers or logical values?

3 visualizaciones (últimos 30 días)
In the following code I encounter the problem in the last line. How to rectify this? The integer value is positive , i.e., i=1:3, but I am getting this error.
uxc = getpdb('1UXC');
isTYR = ({uxc.Model.Atom.resName} == "TYR")
isTYR = 1×808 logical array
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
uxcTYR = uxc.Model.Atom(isTYR) % Extracts particulars of only TYR
uxcTYR = 1×63 struct array with fields:
AtomSerNo AtomName altLoc resName chainID resSeq iCode X Y Z occupancy tempFactor segID element charge AtomNameStruct
TyrXYZ = [uxcTYR.X; uxcTYR.Y; uxcTYR.Z]' ; %Coordinates of all Tyrosine residues
Tyrcd = {};
Tyrseq = {};
Tyrmass = {};
sizeTyr = size(TyrXYZ);
numTyr = sizeTyr(1) / 21 ;
for i = 1:numTyr
Tyrcd{i} = TyrXYZ((21*i-20):(21*i),:);
Tseq = [uxcTYR.element]' ;
Tyrseq{i} = Tseq((21*i-20):(21*i),:)
end
Tyrseq = 1×1 cell array
{21×1 char}
Tyrseq = 1×2 cell array
{21×1 char} {21×1 char}
Tyrseq = 1×3 cell array
{21×1 char} {21×1 char} {21×1 char}
%COM
Amac_mass = ["A", 71.0788;"R", 156.1875;"N", 114.1038;"D", 115.0886;"C", 103.1388;"E", 129.1155;"Q", 128.1307;"G", 57.0519;"H", 137.1411;"I", 113.1594;"L", 113.1594;"K", 128.1741;"M", 131.1926;"F", 147.1766;"P", 97.1167;"S", 87.0782;"T", 101.1051;"W", 186.2132;"Y", 163.1760;"V", 99.1326];
Tyrmass = {};
for i = 1:numTyr
[ism2,idx2] = ismember(Tyrseq{i},Amac_mass(:,1));
Tyrmass{i} = [Amac_mass(idx2,:)];
end
Index in position 1 is invalid. Array indices must be positive integers or logical values.

Respuestas (2)

Walter Roberson
Walter Roberson el 24 de Feb. de 2023
ismember returns 0 for indices in the case that the value was not found.
Note that the entries in Tyrseq have not had trailing blanks removed.

Steven Lord
Steven Lord el 24 de Feb. de 2023
If you just want to be able to determine the mass for a specified identifier, I wouldn't use ismember in this case. I'd use a dictionary object. I'm going to start off with a cell array because I don't feel like editing the code further to split this into separate string and numeric arrays.
idAndMass = {"A", 71.0788;"R", 156.1875;"N", 114.1038;"D", 115.0886;"C", 103.1388;...
"E", 129.1155;"Q", 128.1307;"G", 57.0519;"H", 137.1411;"I", 113.1594;...
"L", 113.1594;"K", 128.1741;"M", 131.1926;"F", 147.1766;"P", 97.1167;...
"S", 87.0782;"T", 101.1051;"W", 186.2132;"Y", 163.1760;"V", 99.1326};
D = dictionary([idAndMass{:, 1}], [idAndMass{:, 2}])
D =
dictionary (stringdouble) with 20 entries: "A" ⟼ 71.0788 "R" ⟼ 156.1875 "N" ⟼ 114.1038 "D" ⟼ 115.0886 "C" ⟼ 103.1388 "E" ⟼ 129.1155 "Q" ⟼ 128.1307 "G" ⟼ 57.0519 "H" ⟼ 137.1411 "I" ⟼ 113.1594 "L" ⟼ 113.1594 "K" ⟼ 128.1741 "M" ⟼ 131.1926 "F" ⟼ 147.1766 "P" ⟼ 97.1167 "S" ⟼ 87.0782 "T" ⟼ 101.1051 "W" ⟼ 186.2132 "Y" ⟼ 163.1760 "V" ⟼ 99.1326
Now to use it I can query the dictionary:
values = D(["M", "A", "T"])
values = 1×3
131.1926 71.0788 101.1051
though I'd check if the identifier I'm searching for isKey of the dictionary first, to guard against your sequence having an identifier for which you haven't specified a mass (like "B" in the example below.)
isInDictionary = isKey(D, ["M", "A", "T", "L", "A", "B"])
isInDictionary = 1×6 logical array
1 1 1 1 1 0

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by