Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Variable in a for loop

조회 수: 2 (최근 30일)
Collin McCabe
Collin McCabe 2020년 10월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
In a for loop that I'm writing, I am trying to display two variables set as vectors like:
x = 1:50
y = x
x = 1:25
However, when I try to display both x and y afterwards, they both display the modified x value. How can I fix this?

답변 (1개)

per isakson
per isakson 2020년 10월 30일
편집: per isakson 2020년 10월 30일
"[...] they both display the modified x value" No they don't. This script
%%
for jj = 1:100
x = 1:12;
y = x;
x = 1:6;
end
% display both x and y afterwards
disp( x )
disp( y )
displays
1 2 3 4 5 6
1 2 3 4 5 6 7 8 9 10 11 12
>>
and
>> whos x y
Name Size Bytes Class Attributes
x 1x6 48 double
y 1x12 96 double

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by