MATLAB Answers

How to append values of a vector in a loop?

1 view (last 30 days)
Abigail Gunderson
Abigail Gunderson on 23 May 2020
Commented: Rik on 23 May 2020
%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);
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?

Sign in to comment.

Answers (0)

Translated by