In the for loop, you only can keep the last result from the for loop. I want to save the data each time I finish from the for loop. I can’t put the index of the for loop because not all variables are satisfying the if statement: my code is:
c=[1 3 2 3 3];p=[0 0 1 2 1];level2=[1 3];
for j=1:length(level2)
for i=1:length(p)
a=[p(i),c(i)]';
if a(1,:)==level2(j)
level3=a(2)
else
end
end
end
So, how can I make level3 as a vector for all results from the for loop? Note that p,c and level2 should be dynamic values, but here they are static to make the example much easier.
You can try following
E.g., you will append result of iteration into the end of current vector.