how can i save the results of multiple executions?

3 visualizaciones (últimos 30 días)
mariam muner
mariam muner el 7 de Feb. de 2023
Respondida: Walter Roberson el 7 de Feb. de 2023
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 comentario
Walter Roberson
Walter Roberson el 7 de Feb. de 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))
ANG = 

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Feb. de 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

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by