What is the answer of [(4 -2 ) /2 , 5 +6 , 7 , 8 ] ? Why does MATLAB output [1 5 6 7 8]?
83 ビュー (過去 30 日間)
古いコメントを表示
When the plus sign is preceded by a blank space:
[(4 -2 ) /2 , 5 +6 , 7 , 8 ]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305800/image.png)
Delete blank space:
[(4 -2 ) /2 , 5+6 , 7 , 8 ]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305805/image.png)
I don't understand why MATLAB will output different results.
Under normal circumstances, shouldn't spaces be ignored?
0 件のコメント
採用された回答
その他の回答 (3 件)
Steven Lord
2023 年 2 月 24 日
1 件のコメント
Stephen23
2023 年 2 月 24 日
編集済み: Stephen23
2023 年 2 月 24 日
There is nothing on that page that explicitly explains how space is interpreted around arithmetic operators when building arrays:
[1 - 2]
[1 -2]
This topic comes up fairly regularly on Answers, indicative of confusion regarding this topic, and that page looks like a good place to document it. None of the other "obvious" pages I found in a quick search now covered this topic either, e.g.:
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!