I have to store 3 sets of data, with for statement

1 Ansicht (letzte 30 Tage)
Devesh Kumar
Devesh Kumar am 21 Jun. 2022
Kommentiert: Devesh Kumar am 28 Jun. 2022
for i = 1:cf_n
x1(i,1) = [2 Vr_on_cf Vr_R1_cf(i) Vr_R2_cf(i) Vr_cf_end]; % Az/D for cross - flow
y1(i,1) = [0 0.15 Az1_D(i) Az2_D(i) 0]; % reduced velocity
end
Here Vr_on_cf,Vr_cf_end is constant = 2.5 and 16 respectivetly , Vr_R1_cf & Vr_R2_cf are vector which contains 3 values say [ a b c] and [d e f], in this particular case cf_n is 3
now I want my output like this
x = [2 2.5 a d 16; 2 2.5 b e 16; 2 2.5 c f 16]; basically 5*3 matrix
how should I run the for loop
  2 Kommentare
Walter Roberson
Walter Roberson am 21 Jun. 2022
for i = 1:cf_n
x1(i,:) = [2 Vr_on_cf Vr_R1_cf(i) Vr_R2_cf(i) Vr_cf_end]; % Az/D for cross - flow
y1(i,:) = [0 0.15 Az1_D(i) Az2_D(i) 0]; % reduced velocity
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Pooja Kumari
Pooja Kumari am 28 Jun. 2022
Dear Devesh,
It is my understanding that you want to store three sets of data using for loop.
Given that Vr_on_cf, Vr_cf_end is constant = 2.5 and 16 respectively, Vr_R1_cf & Vr_R2_cf are vector which contains 3 values say [ a b c] and [d e f], in this particular case cf_n is 3.
You can get the provided output using the following code:
Vr_on_cf = 2.5;
Vr_cf_end = 16;
Vr_R1_cf = [ "a" "b" "c"];
Vr_R2_cf = [ "d" "e" "f"];
% x = [2 2.5 a d 16; 2 2.5 b e 16; 2 2.5 c f 16]; %Required Output
for i = 1:3
x1(i,:) = [2 Vr_on_cf Vr_R1_cf(i) Vr_R2_cf(i) Vr_cf_end] % instead of your provided code, you can use this changed to get the required output
end
Sincerely,
Pooja Kumari

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by