I have one matrix A = [745 678]. I have another matrix B = [745 1].
I want to compute A / B. I want the result to be a [745 678] matrix. So basically every row in A (from 1 to 678) will be divided by the column matrix B. The end result will be all the matrix elements of A divided by the matrix elements of B.

 채택된 답변

Walter Roberson
Walter Roberson 2019년 6월 7일

1 개 추천

In R2016b or later,
A ./ B
In earlier releases,
bsxfun(@rdivide, A, B)

댓글 수: 5

Articat
Articat 2019년 6월 7일
My apologies, I made an error to the question. I just fixed it. I tried this but am still getting an error that: "matrix dimensions must agree."
Which MATLAB release are you using?
@Lane: Then please post the failing code. The suggestions of Walter and John do work:
A = rand(745, 678);
B = rand(745, 1);
C = A ./ B; % >= Matlab R2016b
D = bsxfun(@times, A, B); % All Matlab versions
Articat
Articat 2019년 6월 10일
Was able to figure it out by using the function repmat()
Jan
Jan 2019년 6월 10일
@Lane Dillon: repmat is most likely the least efficient method to solve the problem.

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

추가 답변 (1개)

John D'Errico
John D'Errico 2019년 6월 7일

2 개 추천

Is there a reason why you have not read the getting started tutorials? The manual is always a good thing to read.
C = A./B;

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2019년 6월 7일

댓글:

Jan
2019년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by