What is the proper way to address this array when using an if-then statement with logical operators?
1 回表示 (過去 30 日間)
古いコメントを表示
What is the best way to create arrays for each C1 , C2 , C3 , and C4 based off a logical if statement? The array RATN is a 6X10 array that is used in the calculation of C1-4. I would like to create a 6x10 array for each C1 , C2 , C3 , and C4 based on the index value in which if RATN is greater than 0.1 but less than 2.0 a value is calculated from one equation, but if the value is greater than 2 the value is calculated from a different equation. As I have it set up now C1 is being populated with values calculated from RATN that are greater than 2.0 with the equation that is supposed to be used for values less than 2.0.
0 件のコメント
採用された回答
Voss
2022 年 12 月 5 日
[m,n] = size(ratn);
C1 = zeros(m,n);
C2 = zeros(m,n);
C3 = zeros(m,n);
C4 = zeros(m,n);
idx = ratn < 2 & ratn >= 0.1;
C1(idx) = 0.947 + 1.206.*sqrr(idx) - 0.131.*ratn(idx);
C2(idx) = 0.022 - 3.405.*sqrr(idx) + 0.915.*ratn(idx);
C3(idx) = 0.869 + 1.777.*sqrr(idx) - 0.555.*ratn(idx);
C4(idx) = -0.810 + 0.422.*sqrr(idx) - 0.260.*ratn(idx);
C1(~idx) = 1.232 + 0.832.*sqrr(~idx) - 0.008.*ratn(~idx);
C2(~idx) = -3.813 + 0.968.*sqrr(~idx) - 0.260.*ratn(~idx);
C3(~idx) = 7.423 - 4.868.*sqrr(~idx) + 0.869.*ratn(~idx);
C4(~idx) = -3.839 + 3.070.*sqrr(~idx) - 0.600.*ratn(~idx);
2 件のコメント
zachary owen
2022 年 12 月 6 日
Thank you! If I wanted to find more documentation on this what topics should I search?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!