MATLAB Answers


How to avoid overwriting inside a for loop?

Asked by karishma koshy on 25 Jul 2019
Latest activity Answered by Abhilash Padma on 29 Jul 2019
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.


on 25 Jul 2019
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...
on 25 Jul 2019
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?
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

Sign in to comment.


1 Answer

Answer by Abhilash Padma on 29 Jul 2019

Instead of declaring “frame” as an empty array, declare it as an empty cell array.
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.
Now, the cell array “frame stores every value of each iteration.


Sign in to comment.