Combine output from for loop into one long vecor, then put that row into a cell.

조회 수: 1 (최근 30일)
Hi all,
I have this code, and it works how I would like for the first row, but I am having trouble generalizing it.
y = randi(10,10);
out = [];
m = sparse(y);
for j1 = 1:N
y1 = (j1-1) * ones(1, m(1,j1));
out = [out y1];
end
Thanks in advance.

채택된 답변

Star Strider
Star Strider 2015년 8월 20일
Not certain I understand what you want, but if you want ‘out’ to be a cell array, just address it that way:
out{j1} = [out y1];
  댓글 수: 12
Star Strider
Star Strider 2015년 8월 20일
My pleasure!
I’m very happy we got this sorted!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by