How to put elements from a for loop into an array
2 次查看(过去 30 天)
显示 更早的评论
I have the following for loop that gives values for an output 'COLm' based on inout P which ranges from 0 to Q (where Q is equal to 9 currently). I need the values of COLm to be stored in a 1xQ array for use in another section. How is it possible to store such answers in this way?
Thanks
for P = 0:Q %state values
format long
imag=imread('Oban.tif');
SubPlotxP = Txx + (P*(Rx1x-Txx)/10);
SubPlotyP = Txy +(P*(Rx1y-Txy)/10);
DIVx = SubPlotxP;
DIVy = SubPlotyP;
SubPlotxPRound = round(DIVx);
SubPlotyPRound = round(DIVy);
format long
Elev1xP = ((SubPlotxP)- 207000);
Elev1yP = 913000-SubPlotyP;
Elev1xPRound = round(Elev1xP);
Elev1yPRound = round(Elev1yP);
COL = imag(Elev1xPRound,Elev1yPRound,:);
COLm = COL/100;
0 个评论
采纳的回答
Walter Roberson
2021-2-7
COLm(:,P+1) = COL/100;
However: You said that you want a 1xQ array, but you are executing the loop body Q+1 times. Which P value should not have its result recorded?
7 个评论
Walter Roberson
2021-2-7
COLm = zeros(1,Q+1); %before the loop
%...
COL = imag(Elev1xPRound,Elev1yPRound);
COLm(1,P+1) = COL/100; %in the loop
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!