Matrix division "in scalar way"
61 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have following formula
X=Y/(Z*2);
Where
Y is a vector predefined 1x200 - let say 1, 2, 3, 4, 5 .... 200
Z is also a vector predefined 1x200 - let say 1, 2, 3, 4, 5 .... 200
If I run it in sacalar I should always get 0.5 (1/(1*2) = 2/(2*2) =...= 200/(200*2)
I would like to get this same kind of results but stored in 1x200 array/vector when I run it as a matrix operation.
So X = [0,5 , 0,5 , .... 0,5]
How to do that?
If I run it like:
X=Y/(Z.*2);
I only get single result
and If I run it like:
X=Y\(Z*2);
I got a nonsense 200x200 matrix.
I will be thankful for any tips!
1 件のコメント
採用された回答
Alan Stevens
2020 年 8 月 31 日
X = Y ./ (Z .* 2);
Note the dot by the divide sign.
2 件のコメント
madhan ravi
2020 年 8 月 31 日
Read the link KSSV and Stephen Cobeldick links, by the way .* is simply *
その他の回答 (1 件)
KSSV
2020 年 8 月 31 日
編集済み: KSSV
2020 年 8 月 31 日
Read about element by element operations in MATLAB. https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html#:~:text=Array%20operations%20execute%20element%20by%20element%20operations%20on%20corresponding%20elements,location%20in%20the%20second%20operand.
X=Y./(2*Z);
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!