필터 지우기
필터 지우기

multiplying 5*5 matrix to a vector on an element by element basis using loops

조회 수: 3 (최근 30일)
mohamed samhy
mohamed samhy 2022년 3월 30일
답변: Victor 2022년 3월 31일
Hi all,
i need to write a code that multiplies the matrix A and the vector B defined below on an element-by-element basis using loops in my code.
A = [1 12 22 10 18; 20 8 13 2 25; 6 19 3 23 14; 4 24 17 15 7; 11 21 16 5 9];
B = [9 7 11 4 23];
thanks in advance for your support
  댓글 수: 2
James Tursa
James Tursa 2022년 3월 30일
What have you done so far? What specific problems are you having with your code? The algorithm can be found here:
mohamed samhy
mohamed samhy 2022년 3월 30일
i need help using loops to multiply element by element

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

답변 (1개)

Victor
Victor 2022년 3월 31일
Are you required to use for loops to multiply element by element here or could you make use of standard Matlab functionality such as the code snippet below?
C = A .* B;
One way of doing this using for loops is shown below
C = zeros(size(A)); % preallocate C
for i = 1:size(A,1)
for k = 1:size(A,2)
C(i,k) = A(i,k) * B(k);
end
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by