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

1 vue (au cours des 30 derniers jours)
Devesh Kumar
Devesh Kumar le 21 Juin 2022
Commenté : Devesh Kumar le 28 Juin 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 commentaires
Walter Roberson
Walter Roberson le 21 Juin 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
Devesh Kumar
Devesh Kumar le 21 Juin 2022
Thanks allot @Walter Roberson

Connectez-vous pour commenter.

Réponse acceptée

Pooja Kumari
Pooja Kumari le 28 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by