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

1 vue (au cours des 30 derniers jours)
Sun Heat
Sun Heat le 5 Oct 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

Réponse acceptée

KSSV
KSSV le 5 Oct 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

Plus de réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Oct 2018
Modifié(e) : KALYAN ACHARJYA le 5 Oct 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 commentaire
KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Oct 2018
Modifié(e) : KALYAN ACHARJYA le 5 Oct 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by