Info

この質問は閉じられています。 編集または回答するには再度開いてください。

A strange result with vectors

1 回表示 (過去 30 日間)
metin yilmaz
metin yilmaz 2020 年 11 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
When I create 1:3:5 matlab turns 1 4, a row matrix.
why does matlab ignores .* between two vectors?
1:3:5 .* 1:3:5 turns out that 1 4.
But when I write 1:3:5 1:3:5 matlab turns "unexpected matlab expression".
Thank you.

回答 (1 件)

Rishik Ramena
Rishik Ramena 2020 年 11 月 5 日
The precedence of .* operator is higher than : operator. You can find more about operator precedence in MATLAB here. So you can get the desired output by using parentheses as shown (1:3:5).*(1:3:5).
1:3:5.*1:3:5 is interpreted as:
1:(3:(5.*1):3):5 -> 1:(3:5:3):5 -> 1:3:5 -> [1,4]
Also note that the .* operator is not being ignored.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by