フィルターのクリア

Loop won't run past first loop, what am I doing wrong here?

1 回表示 (過去 30 日間)
Laasya
Laasya 2023 年 11 月 28 日
回答済み: Walter Roberson 2023 年 11 月 28 日
I made a matrix with double values that the loop traverses through. Each loop, a variable is set to the row number, does the calculations, then inputs the value into the matrix on different new column. Everything inside the loop is correct, but for some reason, it just does the first row and then stops.
D = 1.056;
m = 0.040;
a=0
a = 0
for r=1+a
A = (C{r,2}*0.5)^2*pi;
Q = A*C{r,3};
C{r,4} = Q;
R = (D*C{r,3}*C{r,2})/m;
C{r,5} = R;
a=a+1;
end
Undefined variable 'C'.
  1 件のコメント
Chunru
Chunru 2023 年 11 月 28 日
"for r=1+a" will loop only once. How many times do you want to loop? Try to post an excutable code segment (with all variables defined) for further assistance.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 11 月 28 日
D = 1.056;
m = 0.040;
numrow = size(C,1);
for r = 1 : numrow
C2 = C{r,2};
C3 = C{r,3};
A = (C2*0.5).^2*pi;
Q = A .* C3;
C{r,4} = Q;
R = (D .* C3 .* C2)/m;
C{r,5} = R;
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by