Making accurate graphs of vectors calculated in while loop
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am making a while loop calculate my temperatures using the temperature from the previous loop as an input temperature for a heatflux-function. This function works properly and shows as outputs the right temperatures. These are stored in T_stored(i) and the heat input is stored in Q(i). Can anyone show me how to make an accurate graph of T_stored and Q as a function of Progress( which is actually the part of the while-loop that has been completed.
Thank you in advance.
function [] = thermalmodelloop()
clear all
clear global
close all
v = 300;
p = 0.5*10^-3;
angle = 60;
laserpower = 0;
T_initial = 293.15;
h = 40*10.^-3; %depth of cone
r_initial = 85*10^-3; %starting radius of cone
z_initial = 0;
N = h / p ;%number of revolutions
dz = p;
dr = p*cotd(angle);
i = 1;
T(1) = T_initial;
while i<(N+1)
r = r_initial - (i+1)*dr;
z = z_initial + (i+1)*dz;
[Q , delta_T, T_end ] = heatflux(v, p, r , angle, T, laserpower);
T = T_end+delta_T;
T_C = T-273.15
Q_stored(i) = Q;
T_stored(i) = T_C;
Progress = i/N*100;
i = i+1;
end
end
1 个评论
Stephen23
2016-5-5
编辑:Stephen23
2016-5-5
Why do you have these three lines at the start of your function?:
clear all
clear global
close all
At the beginning of your function here are no variables, so clear is completely useless: it does nothing at all. You also do not have any globals, so why bother clearing any globals used in other functions ? Those globals might be important, and they have nothing to do with this function! And there is no mention of any plots or graphics handles in your code, so why close all ?
When you call sin(0) do you expect all figures to close? Do you expect sqrt(4) to delete all variables from the workspace? Does log(7) clear all globals ?
Then why write your own functions to perform such nonsensical actions ?
回答(1 个)
Nikhil Vyas
2016-5-10
Assuming you want to plot the values in Q_stored and T_Stored against the progress of while loop(which is basically the value of i from 1 to N):
t = 1:N
plot(t, Q_stored, t, T_stored);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!