Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1471
Number of posts: 2147

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Storing for loop results in MATLAB. Posted by topeakin on 16 Jun 2010 at 9:57 AM
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.
Report
Re: Storing for loop results in MATLAB. Posted by jjasso5 on 18 Jun 2010 at 10:10 PM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.