Storing for loop results in MATLAB. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Storing for loop results in MATLAB.

Posts: 1Member
for A=0.1:0.1:0.4; % A is 0.1,0.2,0.3 and 0.4 i.e 4 loops or 4 times

C=linspace(10,40,4);%
D =linspace(0.1,0.1,4); %
E = [1 1 1 1]; %
F = [2 2 2 2]; %

G = A/0.001;
K = [20 20 20 20];
N = [30 30 30 30];

R =A./0.003; %%%

Tope = E+(F-4.*(((K+N)./(R+G)).^2).*(D) +0.5).*(sin((pi/180)*C)).^2
end

My question is that how can I save the results in lets say, Tope1,Tope2,Tope3,Tope4 for the first,second,third and fourth iterations respectively?

If I type Tope at the command window, I can results for all 4 iterattions, but I can only retrieve the last one. Thanks a lot.

• Posts: 41Member
I think you're looking for something like this...

A = 0.1 : 0.1 : 0.4;
G = A/0.001;
R = A/0.003;
C = linspace(10, 40, 4);
D = 0.1;
E = 1;
F = 2;
K = 20;
N = 30;
Tope = E + (F - 4.*(((K+N)./(R+G)).^2).*D + 0.5).*(sin((pi/180).*C)).^2

You're getting a row vector, where
Tope = [Tope(1) Tope(2) Tope(3) Tope(4)]

See another example:
http://www.matrixlab-examples.com/iteration.html