フィルターのクリア

Running code for different variable values.

1 回表示 (過去 30 日間)
Jaevon Stewart
Jaevon Stewart 2024 年 3 月 14 日
回答済み: Walter Roberson 2024 年 3 月 15 日
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.

採用された回答

Walter Roberson
Walter Roberson 2024 年 3 月 15 日
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by