String with mask parameter

4 ビュー (過去 30 日間)
julien dannenmayer
julien dannenmayer 2022 年 10 月 7 日
コメント済み: julien dannenmayer 2022 年 10 月 10 日
On my project, I am using a sub-system with a mask which takes a string as a parameter (typically called "topic_name").
Up to now that topic_name is always populated manually (i.e. typing the string whenever we create a new IO).
However, this is time consuming to maintain a system with multiple occurences where just a number changes in the string.
e.g. for the iteration of my "item1", I map various sub-systems with strings "item1/pump1", "item1/pump2", "item1/cold_valve", "item1/hot_valve"... Then I need to do the same with "item2", mapping strings "item2/pump1", "item2"/pump2", "item2/cold_valve", "item2/hot_valve". And so on with item3, item4, etc.
In short this is a nightmare to maintain, and since all items have the same structure, I would like to create a library block using a mask parameter "item_number" so that I can create the mapping once for pump1, pump2, cold_valve, hot_valve, then just populate the item_number for all the instances of item.
Can anyone explain what the syntax would be for itemitem_number/pump1?

採用された回答

Matt J
Matt J 2022 年 10 月 7 日
編集済み: Matt J 2022 年 10 月 7 日
For example,
"item" + (0:3)' + "/" + ["pump1" "pump2" "cold_valve" "hot_valve"]
ans = 4×4 string array
"item0/pump1" "item0/pump2" "item0/cold_valve" "item0/hot_valve" "item1/pump1" "item1/pump2" "item1/cold_valve" "item1/hot_valve" "item2/pump1" "item2/pump2" "item2/cold_valve" "item2/hot_valve" "item3/pump1" "item3/pump2" "item3/cold_valve" "item3/hot_valve"
  2 件のコメント
julien dannenmayer
julien dannenmayer 2022 年 10 月 10 日
Thanks Matt,
However, due to other constraints, I would need " (0:3)' " to be a function argument or a parameter, so that I can write something like
"item" + item_ number + "pump1"
When I try that, I get error "Convertion to uint8 from string is not possible". And if I for item_number to be a string input, I get error "Arrays have incompatible sizes for this operation".
It's like all the basics of string manipulation (including https://nl.mathworks.com/help/matlab/matlab_prog/converting-from-numeric-to-string.html) are discarded...
julien dannenmayer
julien dannenmayer 2022 年 10 月 10 日
For info, I figured that the external library block that I was using required this string to be a char type.
After typecasting, I could get it to work

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by