Effacer les filtres
Effacer les filtres

give matrix element in for loop

1 vue (au cours des 30 derniers jours)
HADIMARGO
HADIMARGO le 21 Juin 2021
Réponse apportée : Jan le 21 Juin 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.

Réponses (1)

Jan
Jan le 21 Juin 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by