how can i save the results of multiple executions?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Walter Roberson
il 7 Feb 2023
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))
Risposte (1)
Walter Roberson
il 7 Feb 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB 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!