multiplying row vector by a scalar

trying to multiply the third row of a matrix by another row, B:
A = data(3, ;).*B
where B is a row vector
Need help finding a way to multiply the 3rd row of my matrix by a scalar value, for example 100.
Is there a way to do this all in one line?
Thanks!

답변 (4개)

VBBV
VBBV 2023년 2월 23일

0 개 추천

A = data(3, :).*B

댓글 수: 5

VBBV
VBBV 2023년 2월 23일
In place of ; you should use :
Kay
Kay 2023년 2월 23일
Hi, yeah sorry that was a typo.
Kay
Kay 2023년 2월 23일
My question still remains: Need help finding a way to multiply the 3rd row of my matrix by a scalar value, for example 100.
John D'Errico
John D'Errico 2023년 2월 23일
They both told you how to do EXACTLY that. Did you try it?
Kay
Kay 2023년 2월 23일
Hi. Im sorry. Im a beginner and from my point of view, they didn't answer my question. I probably didn't word it well enough, and thats my fault. I wasn't trying to be rude. This response feels really harsh.

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

the cyclist
the cyclist 2023년 2월 23일

0 개 추천

You needed a colon in place of that semicolon
A = data(3,:).*B

댓글 수: 3

Kay
Kay 2023년 2월 23일
Hi, yeah sorry that was a typo. My question still remains: Need help finding a way to multiply the 3rd row of my matrix by a scalar value, for example 100.
thanks!
John D'Errico
John D'Errico 2023년 2월 23일
They both told you how to do EXACTLY that. Did you try it?
Kay
Kay 2023년 2월 23일
Hi. Im sorry. Im a beginner and from my point of view, they didn't answer my question. I probably didn't word it well enough, and thats my fault. I wasn't trying to be rude. This response feels really harsh.

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

John D'Errico
John D'Errico 2023년 2월 23일

0 개 추천

I think @Kay needs an example.
A = ones(4,3)
A = 4×3
1 1 1 1 1 1 1 1 1 1 1 1
B = 1:3;
A(3,:) = A(3,:).*B
A = 4×3
1 1 1 1 1 1 1 2 3 1 1 1

댓글 수: 1

Kay
Kay 2023년 2월 23일
Hi. Thanks for this. I think I probably didn't word my question well enough, this isn't what I'm looking for. But thanks for your response!

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

the cyclist
the cyclist 2023년 2월 23일

0 개 추천

% Your matrix
M = magic(4)
M = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
% Your scalar
scalar = 100;
% Multiply the third row of your matrix by your scalar
M(3,:) = scalar .* M(3,:)
M = 4×4
16 2 3 13 5 11 10 8 900 700 600 1200 4 14 15 1

카테고리

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

질문:

Kay
2023년 2월 23일

답변:

2023년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by