how can i plot all for loop's values
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i made a for loop programe ,but when i make plot for value .. the result is point .. how can i save all value of for loop and plot them ??
clear,clc
for th=-25:.1:50;
fai=atand(((750+450.*sin(th)))./(450.*cosd(th)));
force=(4000*cosd(th)*1500)/(450*sind(fai));
l=450*cosd(th)/cosd(fai);
plot(th,force)
end
0 Commenti
Risposte (2)
mohammad Al-Kayyali
il 13 Ott 2011
hi mo ,
Try to use dummy variable to save your data then use the plot function as follows :
z=1;for th=-25:.1:50;
fai=atand(((750+450.*sin(th)))./(450.*cosd(th)));
force=(4000*cosd(th)*1500)/(450*sind(fai));
thdummy(z)=th;
forcedummy(z)=force;
z=z+1;
l=450*cosd(th)/cosd(fai);
end
plot(thdummy,forcedummy)
0 Commenti
Matt Tearle
il 13 Ott 2011
Why are you using a for-loop at all? These are all vectorized operations.
th=-25:.1:50;
fai=atand(((750+450.*sind(th)))./(450.*cosd(th)));
force=(4000*cosd(th)*1500)./(450*sind(fai));
l=450*cosd(th)./cosd(fai);
plot(th,force)
Note the use of the elementwise multiply and divide everywhere.
3 Commenti
Matt Tearle
il 13 Ott 2011
Run the code I posted, then check your workspace. The first line creates a vector of values for th. Then fai, force, and l are also vectors, because all operations are performed element-by-element. No loops required. That's MATLAB for you.
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!