Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Devesh Kumar
Devesh Kumar el 21 de Jun. de 2022
Comentada: Devesh Kumar el 28 de Jun. de 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 comentarios
Walter Roberson
Walter Roberson el 21 de Jun. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Pooja Kumari
Pooja Kumari el 28 de Jun. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by