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

 Akzeptierte Antwort

Sam Chak
Sam Chak am 16 Apr. 2022

1 Stimme

for x =1:5
y(x) = x*x;
end
disp(y)

6 Kommentare

ADNAN KIRAL
ADNAN KIRAL am 16 Apr. 2022
Bearbeitet: ADNAN KIRAL am 16 Apr. 2022
thanks for reply,
Hi there,
Just one more question please. If i have a data as a matrix. like this
x=data(:,1)
Can I get that ?
THANKS again.
Sam Chak
Sam Chak am 16 Apr. 2022
Bearbeitet: Sam Chak am 16 Apr. 2022
Do you mean storing data like this?
for i = 1:5
x(i) = i;
y(i) = x(i)*x(i);
end
data = [x' y']
save xydata.mat
ADNAN KIRAL
ADNAN KIRAL am 16 Apr. 2022
thanks for the reply. I have data in a matrix.
the data is attached here. instead of "x" values, I want to use these values.
thanks again.
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 am 16 Apr. 2022
i guess it is ok. thnaks again @Sam Chak
all the best.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by