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

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 2020년 2월 25일
Apologies, terrible question. I will explain it better

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2020년 2월 25일

0 개 추천

No, a loop is the best way.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 2월 25일

답변:

2020년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by