how to save variables in a for loop

5 次查看(过去 30 天)
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