How to append values of a vector in a loop?
Afficher commentaires plus anciens
%len = length(vector) its the length of a part of a cell array
%a = the above vector that contains string components
for i= 1:len-1
if strcmp(a(i),a(i+1))
scores(end+1)= scores(i);
end
end
I try to run the above part and it works for some of my files but for others it come up with the error:
error: scores(437): out of bound 436
I want it to append a new element (the same value as the indexed element) to the end of the scores vector if the string in the vector a is equal to the next string in the vector a
1 commentaire
Rik
le 23 Mai 2020
Why do you want to do it in a loop like this?
With this description of your code and data, I don't see any reason for this error. Can you share the actual variables?
Réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!