MATLAB Answers

0

For loop returns vector with different sizes, how to put them in a single matrix?

Asked by Pratyush Das on 7 Jul 2019
Latest activity Answered by Pratyush Das on 25 Aug 2019 at 14:57
I have a for loop which returns a vector after each iteraion, but the vector length is different each time. How to store the results in a matrix or table or whatever , so that I can use the values for other operations.
for k = 1:length(sect)
SS(k,:) = find(TS{:,2}<sect(k+1) & TS{:,2}>=sect(k) );
k+1;
end

  4 Comments

Show 1 older comment
Any example? Say the first iteration has 88 elements and the second 108. But I do not know the rest of the. How do I write the code in the for loop ?
SS{k} = find(....)
By the way you should consider using histc or histcounts or discretize to determine the bin numbers.
Attach small part of your data here.

Sign in to comment.

1 Answer

Answer by Pratyush Das on 25 Aug 2019 at 14:57
 Accepted Answer

SS{k} = find(....)
Thank you Walter Roberson for the answer. It creates a cell array.

  0 Comments

Sign in to comment.