Elementwise division in matrix notation
조회 수: 16 (최근 30일)
이전 댓글 표시
Dear all,
I am trying to write the following code in matrix notation:
A = B. / C;
A, B and C are column vectors with 1435 rows.
I have already managed to do this with multiplication, i.e.:
D = E.*F;
This is equivalent to
D = diag(F)*E;
Also in this case D, E and F are also column vectors with 1435 rows.
I want to do this because it is more foolproof and does not give results if the dimensions do not match.
Best,
Hylke
댓글 수: 6
채택된 답변
추가 답변 (1개)
Image Analyst
2022년 1월 28일
편집: Image Analyst
2022년 1월 28일
Try getting rid of the space between the dot and the slash:
A = B ./ C;
If the length of B and C don't match, you might want to consider if you even want to divide them. Like, WHY don't they match? If one is shorter to you want to just assign the "left over" elements to something specific, like 0 or 1 or B or C or something?
댓글 수: 4
Image Analyst
2022년 1월 28일
Not using diag() will also give an error. Look:
B = rand(10, 1);
C = rand(2, 1);
A = B ./ C;
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!