how to save variables in a for loop

6 visualizaciones (últimos 30 días)
ADNAN KIRAL
ADNAN KIRAL el 16 de Abr. de 2022
Comentada: ADNAN KIRAL el 16 de Abr. de 2022
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

Respuesta aceptada

Sam Chak
Sam Chak el 16 de Abr. de 2022
for x =1:5
y(x) = x*x;
end
disp(y)
  6 comentarios
Sam Chak
Sam Chak el 16 de Abr. de 2022
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 el 16 de Abr. de 2022
i guess it is ok. thnaks again @Sam Chak
all the best.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by