take the real data type of parameters from the Simulink model
1 回表示 (過去 30 日間)
古いコメントを表示
Hi! What do you think about this?
I'm using R2009b Matlab version. I have my_para.mat set of parameters that are used in my_model.mld.
My problem is related to the data type of these parameters. Even if my 'para1' parameter is used as uint16 in the Simulink model, Matlab takes it as double. What can I do to take the real data type directly from the model? I have a GUI interface and I need only to display these real data types.
Thank you in advance!
4 件のコメント
TAB
2011 年 9 月 15 日
I still confused what you want to do.
If you want to get the data types of parameters from model workspace, take handle of model and use get_param() function.
See
http://www.mathworks.in/help/toolbox/simulink/ug/f4-140122.html
See 'model construction commands' to see how to use get_param().
回答 (7 件)
Fangjun Jiang
2011 年 9 月 15 日
When you create your .mat file, use the following to set up the value and then save to the .mat file.
para1=uint16(25);
When you try to get the data type of this parameter, use
DataType=class(para1)
4 件のコメント
Fangjun Jiang
2011 年 9 月 15 日
get_param() works for vector input which means if you have 100 block handles, it will give you 100 output data types. But, would it be better to show the data type in model directly. Your GUI would be hard to show hundreds of parameters anyway. In your Simulink model,click meny Format->Port/Signal Displays, check "Port Data Types"
James
2011 年 9 月 15 日
In the Simulink model use a Data Type Conversion block. It's in Commonly Used Blocks.
When I've wrestled with this I found it easiest (i.e. most predictable/reliable) to take in everything as doubles and to output it as doubles in and out of the Simulink model.
3 件のコメント
James
2011 年 9 月 15 日
I was referring to the data.
Turn on the view Fangjun referred to, where port data types are displayed on the model. It will let you confirm what the actual data types are.
Diana Acreala
2011 年 9 月 19 日
9 件のコメント
Fangjun Jiang
2011 年 9 月 21 日
See the comment in my answer. DataType=get_param(BlockFullPath,'OutDataTypeStr')
TAB
2011 年 9 月 20 日
Your question is still not clear. What is 'corresponding block '
If you mean 'constant' blocks and you want output datatype of these blocks then try this.
h=load_system('yourmodel');
CBlks= find_system(h, 'SearchDepth',2,'FindAll', 'on', 'BlockType', 'Constant');
if(~isempty(CBlks))
CBlks_Name=get_param(CBlks,'Name');
CBlks_DType=get_param(CBlks,'OutDataTypeMode');
end
'CBlks_Name' will store names of constant blocks and 'CBlks_DType' will store thier output datatypes. You can send them anywhere you want.
TAB
2011 年 9 月 20 日
You may using parameter name in the 'Constant value' field of constant block.
Try
CBlks_ValStr=get_param(CBlks,'Value');
using get_param() you can retrieve the properties of model and any blocks. Similarly you can set thier properties using set_param().
For list of model and block properties please see
TAB
2011 年 9 月 22 日
hhmmm......
Answer is in you question itself (See comment). gcs specifies the currently selected system or subsystem.
Take handle of model and use it with find_system(). Also go through the option available for find_system().
doc find_system
mdlhandle=load_sysetm('MyModel');
blks = find_system(mdlhandle, 'Type','block');
% OR
blks = find_system(mdlhandle, 'FindAll','on','Type','block');
listblks = get_param(blks, 'BlockType');
listblksname = get_param(blks, 'Name');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Event Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!