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

1 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2018-10-5
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

更多回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018-10-5
编辑:KALYAN ACHARJYA 2018-10-5
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2018-10-5
编辑:KALYAN ACHARJYA 2018-10-5
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by