How to append values of a vector in a loop?

%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

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?

Sign in to comment.

Answers (0)

Categories

Asked:

on 23 May 2020

Commented:

Rik
on 23 May 2020

Community Treasure Hunt

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

Start Hunting!