フィルターのクリア

How to divide a matrix by certain numbers?

1 回表示 (過去 30 日間)
Royvg94
Royvg94 2015 年 9 月 23 日
コメント済み: Star Strider 2015 年 9 月 23 日
I want to divide a matrix by a column vector in this way:
(4 2 3 8;7 9 1 5;6 4 8 3) / (4;8;2)
and then the result i want to get is:
(4/4 2/4 3/4 8/4;7/8 9/8 1/8 5/8;6/2 4/2 8/2 3/2)

採用された回答

Star Strider
Star Strider 2015 年 9 月 23 日
Try this:
A = [4 2 3 8;7 9 1 5;6 4 8 3];
B = [4;8;2];
format rat
Q = bsxfun(@rdivide, A, B)
Q =
1 1/2 3/4 2
7/8 9/8 1/8 5/8
3 2 4 3/2
  2 件のコメント
Royvg94
Royvg94 2015 年 9 月 23 日
What means format rat? And what does it do?
Star Strider
Star Strider 2015 年 9 月 23 日
The format rat sets the format in the Command Window to rational fraction approximation, since I thought that is what you wanted. (See the documentation on format for a full description of that and other options.) This just affects the Command Window output, and full double-precision representation is maintained internally.

サインインしてコメントする。

その他の回答 (1 件)

Thorsten
Thorsten 2015 年 9 月 23 日
A./repmat(v, 1, size(A, 2))
  2 件のコメント
Royvg94
Royvg94 2015 年 9 月 23 日
Can you explain this a bit more?
Thorsten
Thorsten 2015 年 9 月 23 日
You expand the column vector v to the size of the matrix by replicating it using repmat, then you use point-wise division ./

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by