Borrar filtros
Borrar filtros

give matrix element in for loop

1 visualización (últimos 30 días)
HADIMARGO
HADIMARGO el 21 de Jun. de 2021
Respondida: Jan el 21 de Jun. de 2021
hi. i want to make this kind of code in matlab:
a = [ 1 2 3 ];
b1 = 1;
b2 = 3;
b3 = 8;
for i=1:1:3
a(1,i) = b(i)
end
result ==> a = [1 3 8];
how can i create this kind of code in matlab?
pls pay attention i just want to give b1,b2,b3 to a matrix just with "for" loop.

Respuestas (1)

Jan
Jan el 21 de Jun. de 2021
Welcome to Matlab.
This is the most frequently asked question and a severe mistake of beginners. Do not hide indices in the names of variables. This is a shot in your knee and demands for ugly methods to access the variables later on. See this excellent tutorial:
The trivial solution is: Do not create b1, b2, b3, ... but store them in a vector from the beginning.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by