I'm trying to create Matrices Index or subscript ?

4 vues (au cours des 30 derniers jours)
Abdulaziz
Abdulaziz le 12 Sep 2012
Hello guys
I wish you help me with my issue. I am trying to put a subscript or index to a group of matrices. I tried the following short code which did not work. The code is showed below.
>> x=[1 2 3;4 5 6;7 8 9]
x =
1 2 3
4 5 6
7 8 9
>> u=1;
>> for i=1:3
y_u=i*x;
u=u+1;
end
>> y_1
??? Undefined function or variable 'y_1'.
Thank you in advance

Réponse acceptée

Matt Fig
Matt Fig le 12 Sep 2012
Modifié(e) : Matt Fig le 12 Sep 2012
Do not program that way in MATLAB!
You want this:
x = [1 2 3;4 5 6;7 8 9];
for ii = 1:3
y{ii} = ii*x; % Notice {} and not ()
end
Now you have a cell array that has as each element a matrix:
y{1}
y{2}
y{3}
If you want to make ii go much further than 3, you should pre-allocate the memory for y first...
  2 commentaires
Andrei Bobrov
Andrei Bobrov le 12 Sep 2012
x = [1 2 3;4 5 6;7 8 9];
y = bsxfun(@times,x,reshape(1:3,1,1,[]));
yout = num2cell(y,[1 2]);
Abdulaziz
Abdulaziz le 14 Sep 2012
Thank you Matt FIG this was really helpful
I appreciate your time

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by