Easier method to iterative matrix multiplication?

n = 10
matrix = zeros(n,n);
matrix(1,1:n) = 2
matrix1 = zeros(n,n);
matrix1(1:n,1) = 4
for i = (1:n)
matrix(i+1,1:n) = matrix(i,1:n)*matrix1;
end
matrix
Outputs:
matrix =
2 2 2 2 2 2 2 2 2 2
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
matrix1 =
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
matrix =
2 2 2 2 2 2 2 2 2 2
80 0 0 0 0 0 0 0 0 0
320 0 0 0 0 0 0 0 0 0
1280 0 0 0 0 0 0 0 0 0
5120 0 0 0 0 0 0 0 0 0
20480 0 0 0 0 0 0 0 0 0
81920 0 0 0 0 0 0 0 0 0
327680 0 0 0 0 0 0 0 0 0
1310720 0 0 0 0 0 0 0 0 0
5242880 0 0 0 0 0 0 0 0 0
20971520 0 0 0 0 0 0 0 0 0
The point is that matrix will have more values added to it. matrix 1 will be filled with many different values. I'm trying to find an easier way than a for loop.
matrix1 is made to be that way for easier explanation

2 commentaires

Looks a bit strange. matrix(i+1,1:n) will be an [1 x n] array, on the right-hand-side matrix(i,1:n) will have the same size. That will force matrix1 to be a scalar for matrix-multiplication to work. Perhaps you want elementwise multiplication? Or some slightly different operation?
arthurk
arthurk le 25 Fév 2020
Apologies, terrible question. I will explain it better

Connectez-vous pour commenter.

 Réponse acceptée

Plus de réponses (0)

Catégories

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by