How to store all the A matrix that I have got from every iteration
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ashraf Zaman
am 31 Dez. 2021
Beantwortet: Walter Roberson
am 31 Dez. 2021
for a = linspace(15,75,5)
theta0 = a
y = ((tan(theta0)*x)) - (g*((x.^2))./(2*((v0*cos(theta0)).^2))) + y0
A = [theta0 y]
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 31 Dez. 2021
a_vals = linspace(15,75,5)
num_a = length(a_vals);
A = zeros(num_a, 2);
for a_idx = 1 : num_a
a = a_vals(a_idx);
theta0 = a;
y = ((tan(theta0)*x)) - (g*((x.^2))./(2*((v0*cos(theta0)).^2))) + y0
A(a_idx, :) = [theta0 y];
end
0 Kommentare
Weitere Antworten (1)
Jonas
am 31 Dez. 2021
is y a single value? then A would be a row vector. you can initialize your A before the loop as A=nan(numel(linspace(15,75,5)),2) and change the A line to A(a/15,:)= [theta0 y]
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!