Naming signal in simulink based on workspace variable value.

3 ビュー (過去 30 日間)
IPro
IPro 2023 年 5 月 4 日
編集済み: Fangjun Jiang 2023 年 5 月 8 日
In simulink, I would like to set the signal names based on the string values contained in a workspace variable.
Example:
In the out.simout field, I get two subfields named "signal1" and "signal2". Instead, I would like them to be named based on the string values contained in a workspace variable.
Is there any solution to this? Thanks!
PS: A simple workaround would be to name manually the two step signals in the Simulink model. Then, the out.simout fields would inherit the names defined in simulink. However, this is not convenient when there are multiple signals.
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2023 年 5 月 4 日
Don't understand your question. Assume your have a="string1", b="string2" in workspace. You have to associate them with the two blocks in Simulink. In terms of the amout of work, that is the same as labeling the two signal lines as "string1" and "string2".
Are you asking if you could type in a, instead of "string1" in case the string is really long?
IPro
IPro 2023 年 5 月 5 日
Indeed. I would like to use the variable name,e.g. "a" in your example, which contains the string "string 1". That's convenient, especially if e.g. there are many signals bundled together, whose desired names are saved in a variable, e.g.
a = [{'string1', 'string2', 'string3'];

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

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 5 月 5 日
It can't be done like a numerical parameter, where you can type in e.g. pi, instead of 3.1415926535
But it can be done through a script. Do a for-loop for multiple blocks/signal lines.
lh=get_param('PathToBlock','LineHandles');
line=lh.Outport;
set_param(line(1),'Name','ThisIsMySignalName')
or
a = {'string1', 'string2', 'string3'};
set_param(line(1),'Name',a{1});
  2 件のコメント
IPro
IPro 2023 年 5 月 8 日
Thanks for the answer. Your solution sets the name of the Simulink line, but not the name of the signals contained in that line. I would like to change the name of the signals instead.
Fangjun Jiang
Fangjun Jiang 2023 年 5 月 8 日
編集済み: Fangjun Jiang 2023 年 5 月 8 日
That is confusing. The name of the line IS the name of the signal. You have to provide an example to clarify it.

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

カテゴリ

Help Center および File ExchangeString についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by