Hello, My code is pretty straightforward
for x = 1:3
y = pi/x
end
I want to get the value of y for each x (i.e. x = 1, x = 2, x =3). But when I run this code, I only get the value of y for x = 3 in my workspace.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 12월 6일
편집: Andrei Bobrov 2015년 12월 6일

0 개 추천

y = zeros(3,1);
for x = 1:3
y(x) = pi/x;
end
or without loop
x = 1:3;
y = pi./x;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Statics and Dynamics에 대해 자세히 알아보기

태그

질문:

2015년 12월 6일

편집:

2015년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by