Index in position 1 is invalid. Array indices must be positive integers or logical values?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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")
uxcTYR = uxc.Model.Atom(isTYR) % Extracts particulars of only TYR
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
%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
0 Commenti
Risposte (2)
Walter Roberson
il 24 Feb 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
il 24 Feb 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}])
Now to use it I can query the dictionary:
values = D(["M", "A", "T"])
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"])
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!