how we can store each and every value in nested for loop.

1 visualización (últimos 30 días)
Sun Heat
Sun Heat el 5 de Oct. de 2018
Editada: KALYAN ACHARJYA el 5 de Oct. de 2018
d=linspace(2,4,3);
for t=1:length(d)
c(t)=d(t)^2;
PL=linspace(0.8,1,3);
for q=1:length(PL)
c1(q,t)=PL(q)^2;
N=linspace(11,13,3);
for y=1:length(N)
c2(y,q)=N(y)^2;
end
end
end

Respuesta aceptada

KSSV
KSSV el 5 de Oct. de 2018
d=linspace(2,4,3);
c = zeros([],[]) ;
c1 = zeros([],[]) ;
c2 = zeros([],[],[]) ;
for t=1:length(d)
c(t)=d(t)^2;
PL=linspace(0.8,1,3);
for q=1:length(PL)
c1(q,t)=PL(q)^2;
N=linspace(11,13,3);
for y=1:length(N)
c2(y,t,q)=N(y)^2;
end
end
end

Más respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 5 de Oct. de 2018
Editada: KALYAN ACHARJYA el 5 de Oct. de 2018
Here already value stored in each iteration
d=linspace(2,4,3);
PL=linspace(0.8,1,3);
N=linspace(11,13,3);
for t=1:length(d)
c(t)=d(t)^2;
for q=1:length(PL)
c1(q,t)=PL(q)^2;
for y=1:length(N)
c2(y,q)=N(y)^2;
end
end
end
Check result in command window: >> c
c =
4 9 16
>> c1
c1 =
0.6400 0.6400 0.6400
0.8100 0.8100 0.8100
1.0000 1.0000 1.0000
>> c2
c2 =
121 121 121
144 144 144
169 169 169
>>
  1 comentario
KALYAN ACHARJYA
KALYAN ACHARJYA el 5 de Oct. de 2018
Editada: KALYAN ACHARJYA el 5 de Oct. de 2018
For example
when t=1 c(1)=2^2=4
when t=2 c(2)=3^2=9
when t=3 c(3)=4^2=16
Please note you have used
linspace(2,4,3)
ans =
2 3 4

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by