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;

采纳的回答

Walter Roberson
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
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
Oscar Zampi
Oscar Zampi 2021-2-7
Thats done the trick.
Thank you so much for your help, it was very useful.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by