Running code for different variable values.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Jaevon Stewart
il 14 Mar 2024
Risposto: Walter Roberson
il 15 Mar 2024
Lets say I have these values here.
theta = 0:2:12.
How do I get matlab to go through the code while the value is zero, get the data, then go through the code while the value is 2, and so on and so forth.
I have been using the for loop...
for i = 1:length(theta)
code code code
code code code
end
but it seems to run a line for all values, save that in an array, then do it for the next line. As a result im running into array incompatibility issues, because my code has 1 by 476 matrix inside of it as well. So I just want to know how yall would go through this.
For example, phi is a 1 by 476 matrix, so when I get to
alpha = theta - phi,
im getting an imcompatible size error. But I want theta to equal zero for the whole code, then I want matlab to come back and solve it while theta is 2, in a clean way.
0 Commenti
Risposta accettata
Walter Roberson
il 15 Mar 2024
theta = 0:2:12;
num_theta = length(theta);
alpha = zeros(num_theta, 147);
for i = 1 : num_theta
this_theta = theta(i);
code code code
alpha(i, :) = this_theta - phi;
end
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements 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!