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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!