Running code for different variable values.

2 visualizaciones (últimos 30 días)
Jaevon Stewart
Jaevon Stewart el 14 de Mzo. de 2024
Respondida: Walter Roberson el 15 de Mzo. de 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.

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by