フィルターのクリア

matlab values returned by getparam ara all considered as string

7 ビュー (過去 30 日間)
Ali
Ali 2022 年 10 月 27 日
回答済み: Walter Roberson 2022 年 11 月 2 日
I have a simulink model from which i import the parameters value in my workspace. Then i want to check if they are either numeric or not so i use the isnumeric function but it says to me that none of the parameters value are numeric because with the get_param any number is considered as a string. So if anyone know of a way to acces the value simulink parameters other than get_param it will be helpfull.
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2022 年 10 月 28 日
編集済み: Fangjun Jiang 2022 年 10 月 28 日
I am curious what is the purpose of your isnumeric() call. Imagine the gain value of the Gain block is '1.1', or 'MyGain', where 'MyGain' is a variable in the workspace. What do you expect get_param('GainBlock','gain') to return to you and what is your next step?
If you state your need or task, there might be a different way.
Ali
Ali 2022 年 11 月 2 日
When i put all my variable and their parameters in my workspace those whose parameters were on or off wich cannot be changed directly in the simulink. These on and off parameters in my workspace were put as 1 and 0. So when i wanted to update them i wanted to see if they were on or off or numeric value to see if they need to be updated.
To do that i used this code :
X=get_param([Simulinkname '/' BlockName, ParameterName]); %get the parameter value from simulink
% if the parameter is numeric it will stay numeric same if it is on or off
B=X;
B =regexprep(B,']',''); % get_param return value in between [ ] so we get rid of them
B =regexprep(B,'[','');
if isnan(str2double(B)) == 1 %we convert the string into numeric and check if it gives a nan answer
%if yes then it means it was an on or off value
end
that way i managed to check if the parameter is numeric or not.

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

採用された回答

Walter Roberson
Walter Roberson 2022 年 11 月 2 日
No, get_param() is the only documented method to retrieve parameters.
Parameter values are stored as character vectors in the model files, both .mdl and .slx files.
It might be the case that when the model is run, that the acceleration phase converts the text to double precision values internally. You can see at https://www.mathworks.com/help/slcompiler/ref/simulink.compiler.modifyparameters.html that for modifying variables that the new values are specified as floating point, not as character vectors, and you can see in the example at https://www.mathworks.com/help/slcompiler/ref/simulink.compiler.gettunablevariables.html that the current value of the tunable variable is floating point rather than character vectors. But at least in that section, there is no simulink.compiler.getparameter function or similar -- the user interface for getting parameters from a model is all character vector.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

タグ

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by