필터 지우기
필터 지우기

Saving data from for loop

조회 수: 1 (최근 30일)
Stephanie Velasco
Stephanie Velasco 2016년 11월 14일
댓글: KSSV 2016년 11월 14일
Hi have been trying to save the data from my for loop each time it runs but for some reason it given the 3 number that i need but with also a lot of other zero in the matrix. Idont know what I'm doing wrong):
for x=30:20:70
for y = 2:2:6
Energy = x*0.239;%covert cal to j
Y= y*60;
power = Energy/Y;
Power(x)=[power];
end
end

답변 (2개)

KSSV
KSSV 2016년 11월 14일
x=30:20:70;
y=2:2:6;
power = zeros(length(x),length(y));
for i=1:length(x)
for j=1:length(y)
Energy = x*0.239;%covert cal to j
Y= y*60;
power(i,j) = Energy/Y;
end
end

Jan
Jan 2016년 11월 14일
Without the loop:
x = 30:20:70;
y = 2:2:6;
Energy = x * 0.239; %covert cal to j
Y = y * 60;
Power = bsxfun(@rdivide, Energy, Y.');
  댓글 수: 1
KSSV
KSSV 2016년 11월 14일
I think for beginners loops are good so that they can learn coding and then go to next level.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by