how to save variables in a for loop

조회 수: 4 (최근 30일)
ADNAN KIRAL
ADNAN KIRAL 2022년 4월 16일
댓글: ADNAN KIRAL 2022년 4월 16일
Dear,
I have a simple "for loop". I want to save every results ("y") in that. Can you please help me with that ?
thanks in advance.
for x=1:1:5
y = x*x
end

채택된 답변

Sam Chak
Sam Chak 2022년 4월 16일
for x =1:5
y(x) = x*x;
end
disp(y)
  댓글 수: 6
Sam Chak
Sam Chak 2022년 4월 16일
How about this one?
% data
data = magic(5)
% assign elements extracted from column 1 of data to vector x
x = data(:,1)
% the square operation
y = x.*x
% display input-output array
table = [x y]
ADNAN KIRAL
ADNAN KIRAL 2022년 4월 16일
i guess it is ok. thnaks again @Sam Chak
all the best.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by