Double or single quotes for `add_line` function?

1 回表示 (過去 30 日間)
Malte Kliemann
Malte Kliemann 2021 年 11 月 11 日
コメント済み: Malte Kliemann 2021 年 11 月 11 日
When calling
add_line("system", "source/1", "sink/1", "autorouting", "on")
the following error is raised: "Input argument 4 is invalid". Not very verbose, unfortunately, but I was able to figure out that autorouting must apparently be placed in single quotes. However, if you only place autorouting in single quotes, MATLAB crashes:
add_line("system", "source/1", "sink/1", 'autorouting', "on")
If you then replace "on" with 'on', it works fine.
So... what's MATLAB's general policy for using double/single quotes? When do functions like add_block, add_line, etc. expect single quotes, when double quotes? This doesn't seem clear in the documentation. There seems to be a tendency to use single quotes, but often enough, double quotes work, as well. So what going on here?

回答 (1 件)

Jan
Jan 2021 年 11 月 11 日
In the documentation doc add_line you find the explanation, that the inoput arguments are "character vectors". This means, that single quotes are required. Many functions working with character vectors accept strings also, so Matlab does not crash in many cases if strings are used. But this drives the functions apart from their specifications.
Look into the documentation and use the documented class for the inputs. Relying on Matlab's smart power to do, what the programmer meant should not be overestimated.
  1 件のコメント
Malte Kliemann
Malte Kliemann 2021 年 11 月 11 日
Thanks. I see where the expected types are specified in the docs now. However, the expected type of out is "block/port name or number character vector". What's that supposed to mean? "block/port name or number" is a description, and the type is "character vector"?

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by