How to append values of a vector in a loop?
Show older comments
%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 Comment
Rik
on 23 May 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?
Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!