Matrices multiplication in a loop

Hello
I have many matrices in two categories say M_i and N_j generated in a for loop. They all have order 2*2. I want to conv each M_i with every N_j i.e.
conv(M_1, N_1)
conv(M_1, N_2) ...
then:
conv(M_2, N_1)
conv(M_2, N_2)...
Any help?

5 commentaires

Rik
Rik le 25 Juil 2019
Why did you use numbered variables? This would be trivial with a nested loop if you had stored them in a cell array.
The best solution is going one step back and not use numbered variables.
Stephen23
Stephen23 le 25 Juil 2019
"I have many matrices ... say M_i and N_j generated in a for loop..."
And that is the bad design decision right there.
If you had simply used indexing (in an ND numeric array or a cell array), then resolving your question would be trivial (hint: by also using indexing). But by creating lots of separate matrices, you will force yourself into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know some of the reasons why:
In contrast, indexing is neat, simple, easy to understand, easy to debug, and very efficient (unlike what you are trying to do). You should use indexing.
doesn't conv accept only 1 dimentional vectors?
Also, if you instantiate 2 3D matrices instead of ixj 2D matrices your life would be easier:
% preallocate:
N = zeros(2,2,n);
M = zeros(2,2,m);
% where n and m are the number of matrices you instantiate today using i and j
% assuming that m ~= n:
for i = 1:n
% N(:,:,i) = whatever calculation you do today
end
for j = 1:m
% M(:,:,j) = whatever calculation you do today
end
tanveer haq
tanveer haq le 25 Juil 2019
I am new to matlab. Therefore, kindly, write a small code for this idea if possible.
tanveer haq
tanveer haq le 25 Juil 2019
Modifié(e) : tanveer haq le 25 Juil 2019
After a long try I succed. Thanks to all of you.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2017b

Modifié(e) :

le 25 Juil 2019

Community Treasure Hunt

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

Start Hunting!

Translated by