フィルターのクリア

Masked Subsystem: How to pass a double vector to a constant?

3 ビュー (過去 30 日間)
Viren
Viren 2014 年 1 月 27 日
回答済み: Fangjun Jiang 2022 年 8 月 1 日
This is a slightly long-winded problem, but should be easy to follow along.
End goal : Input a 'double' vector into a C++ S Function by assigning it to a Constant.
Starting point: A function within the Dialog Callback of my masked subsystem returns the double vector that I need.
Steps in the middle: So I have a double vector as an input, I need a double vector as an output, but I cannot pass the vector directly, because set_param requires that I pass the value as a string.
Problem: What I tried is this:
set_param(gcb,'refNameArray',num2str(refName));
where,
  • gcb (correctly) returns the block from within which I am doing everything.
  • refNameArray is the parameter which needs to be assigned the double vector
  • refName is the vector, in 'double' form, that I have available within the dialog callback of the mask.
I use num2str because I cannot directly assign a vector, I must input it as a string. But, even using num2str, I get an error saying
Invalid Setting in Block <blockName> for parameter 'Value'.
Any suggestions?

回答 (2 件)

Yao Li
Yao Li 2014 年 1 月 28 日
I'm not quite sure about your issue. In general, if you want to assign a value to a parameter in a masked subsystem, add it as a parameter in the Mask Editor as shown in the following link
and then assign the value by
refNameArray=refName;
In case you do need to convert the value to a string first, try converting the array to a cell and converting it back to a double type array by the command sprintf()
  1 件のコメント
Kaustubha Govind
Kaustubha Govind 2014 年 3 月 31 日
I agree. You may to test what num2str(refName) returns to see why that may be resulting an error.

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


Fangjun Jiang
Fangjun Jiang 2022 年 8 月 1 日
I don't know why this old question suddenly appears at the top.
I believe the answer to this question is a trick. Use mat2str(), instead of num2str(). So when evaluated, the string will return an array.
a=1:3
a = 1×3
1 2 3
b=num2str(a)
b = '1 2 3'
c=mat2str(a)
c = '[1 2 3]'
eval(c)
ans = 1×3
1 2 3
eval(b)
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by