How can I store nested for loop values to a cell array?

조회 수: 2 (최근 30일)
Zara Khan
Zara Khan 2019년 2월 26일
댓글: Zara Khan 2019년 3월 2일
I am using a nested for loop. Loop executed values are being stored in cell array but for the first row its working well but from the secong row the last cell value of first row is being repeated . how to solve this ?
  댓글 수: 1
Adam
Adam 2019년 2월 26일
You haven't shown any code so it's rather difficult to guess!

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

채택된 답변

Adam Danz
Adam Danz 2019년 2월 26일
편집: Adam Danz 2019년 2월 26일
Here's a general sketch of how to store data in a cell array within two nested for-loops. If there is something more specific you're looking for, please add some details.
myCell = cell(n,m);
for i = 1:n
for j = 1:m
myCell{i,j} = myFunction(data);
end
end
  댓글 수: 4
Adam Danz
Adam Danz 2019년 2월 27일
There are alternative methods of storing values within a loop but the cell-array you've got is already a good method and it consuming microseconds of time.
When possible, you should always initialize storage variables prior to the loops. Your ell array will always have 'numImages' number of rows but since I cannot run your code, I can't easily tell how many columns it will have. If you can know ahead of time the number of columns, allocate the 'A' array prior to the loops. That will save time.
A = cell(numImages, h)
If you want to understand what part of your code is cuasing the bottleneck, you can run matlab's profile() function which will produce a table of processing times for each component of your code.
profile on
myFunction() %<-- run your function / script
profile viewer
Zara Khan
Zara Khan 2019년 3월 2일
Thank you .

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by