How to avoid overwriting inside a for loop?

I'm using repmat inside my for loop. But at the end of the loop, it saves only the value of last iteration repeating that last value alone. How not to overwrite the values of repmat and extract all the values of iterations.

댓글 수: 3

dpb
dpb 2019년 7월 25일
Well. w/ zero lines of code to look at, the crystall ball has a real workout...
"Use array indices" is the best it can come up with at the moment...
frame=repmat(FR,1,size(centreDark(:,1)))
What do you think the purpose of this line is? What are you trying to do with it?
The loop does indeed not use the indexing variable FR to save anything from one iteration to the other so it does, indeed, overwrite all the variables you create each loop.
The question is, what do you intend/want?
karishma koshy
karishma koshy 2019년 7월 26일
편집: karishma koshy 2019년 7월 26일
I just want to know to which frame the centre and radius point s detected belongs to. And finally I want to make table.with centre radius and frame number

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

답변 (1개)

Abhilash Padma
Abhilash Padma 2019년 7월 29일

0 개 추천

Hi,
Instead of declaring “frame” as an empty array, declare it as an empty cell array.
frame={};
And inside for loop, assign the return value of repmat function to “frame{FR}”.Make the following changes in your for loop which may solve your problem.
frame{FR}=repmat(FR,1,size(centreDark(:,1)));
fr=frame{FR};
Now, the cell array “frame stores every value of each iteration.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2019년 7월 25일

답변:

2019년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by