What is the proper way to address this array when using an if-then statement with logical operators?

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Voss
Voss am 5 Dez. 2022
[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 Kommentare
zachary owen
zachary owen am 6 Dez. 2022
Thank you! If I wanted to find more documentation on this what topics should I search?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by