Build arrays under the for loop

Hi;
for i=1:10
R"i"= nonzeros(D(i,:));
end
I want to create arrays under the for loop. The arrays wont have the same size. For each increment, the name of the array should be R + the increment number (R1, R2, R3 ....).
The desired result is 10 vectors R1 to R10.
Any hints to do it ?
Thank you in advance

댓글 수: 1

Stephen23
Stephen23 2023년 2월 13일
Use indexing. Indexing is a MATLAB superpower. If you do not use indexing, then using MATLAB will be very ... difficult.

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

답변 (1개)

KSSV
KSSV 2023년 2월 13일
편집: KSSV 2023년 2월 13일

0 개 추천

R = cell(10,1) ;
for i=1:10
R{i}= nonzeros(D(i,:));
end
You can access by R{1},R{2},...R{10}. R is a cell array. You need not to name it as R1, R2...R10.

댓글 수: 1

Mohamed Zied
Mohamed Zied 2023년 2월 14일
The aim is to use this arrays with distributionFitter. I build a cell array, but it couldn't be used with distributionFitter. That's why I am looking for another solution.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2023년 2월 13일

댓글:

2023년 2월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by