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

2 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2022-6-21
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

请先登录,再进行评论。

采纳的回答

Pooja Kumari
Pooja Kumari 2022-6-28
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by