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
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
댓글 수: 0
추가 답변 (1개)
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
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 Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!