how can i save the results of multiple executions?
3 次查看(过去 30 天)
显示 更早的评论
hello
if i have the fallowing situation
t=0.1:1:10
for t-ang=t*pi/18
function that depend on t-ang
then i plot the result of this function with the t-ang
end
so the function execuited periodically for each value of t and plot each case.
but it only give me the last value of the fuction by overwriting previous results how can i save the results of each value
1 个评论
Walter Roberson
2023-2-7
for t-ang=t*pi/18
... does that mean you are calculating
syms t ang
ANG = simplify(solve(t-ang == t * sym(pi) / 18, ang))
回答(1 个)
Walter Roberson
2023-2-7
You should learn this pattern:
tvals = 0.1:1:10;
num_t = numel(tvals);
results = zeros(num_t,1);
for t_idx = 1 : num_t
t = tvals(t_idx);
value = some calculation in t;
results(t_idx) = value;
end
plot(tvals, results)
When you use this pattern, the entries in tvals do not need to be sorted or equally spaced or unique. In some cases where those do happen to be the case, you can abbreviate the code. For example,
results = zeros(10,1);
for K = 1 : 10
value = some calculation in (K-0.9);
results(K) = value;
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!