take the real data type of parameters from the Simulink model

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 Commenti

Can you give some more detail? How you are exporting the parameter values from model to .mat file?
Well...I have created my_para.mat and I know for sure that these are used in the model. After that i'm playing with this .mat file.
Well...I have created my_para.mat and I know for sure that these are used in the model. After that i'm playing with this .mat file.
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().

Accedi per commentare.

Risposte (7)

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 Commenti

Ok i think that i already used this line...
WS = whos('-file', FileName);%now WS will contain all parameters from my_para.mat
After that comes:
data_type=WS(1,1).class;% this will show 'double' because of Matlab
I want to see in my interface the real data type fot every parameter directly from my model in Simulink.
For that, you need to do DataType=get_param(BlockFullPath,'OutDataTypeStr'), or get_param(BlockFullPath,'CompiledPortDataTypes').
BlockFullPath is the path of the block like 'untitled/Constant'.
If you set para1=uint16(25) in workspace and use it for the Constant block and set its "Sgnal Attributes", "Output data type" as "Inherit: Inherit from 'Constant value'" through its dialog, the output data type of the Constant block will be 'uint16'.
But i have hundreds of parameters used in my model...
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"

Accedi per commentare.

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 Commenti

Sorry.. I can't understant the last part of your message..'to take in everything as doubles and to output it as doubles in and out of the Simulink model.'
What I need is to display on my GUI interface the real data type of my parameters used in the model... This block is not helping unfortunately.
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.

Accedi per commentare.

Hello! Can anybody help me with another ideea??

9 Commenti

If you could clarify your question. I think it's still not clear from all the comments. "Even if my 'para1' parameter is used as uint16 in the Simulink model, Matlab takes it as double"?
1. What is class(para1) from the .mat file?
2. When you use 'para1' in the block, did you use uint16(para1)?
3. Why did you say "my 'para1' parameter is used as uint16 in the Simulink model"?
I have 200 parameters used in a simulink model and these parameters are saved parameters.mat. I have a GUI interface where I need to display their data type. At the beginning of my application I used this line:
WS = whos('-file', FileName);
Now WS will contain all the parameters from the file parameters.mat.
If I type in Command Window WS then this will appear:
200x1 struct array with fields:
name
size
bytes
class
global
sparse
complex
nesting
persistent
If I type in Command Window WS(1,1).name then this will appear:
>> WS(1,1).name
ans =
Diana_param
If I type in Command Window WS(1,1).class then this will appear:
>> WS(1,1).class
ans =
double
So on my interface I will see 'double'...But the thing is that when I have created the model in Simulink I used this parameter 'Diana_param' as uint16.
So I want to see on my interface uint16 not double.
Okay, so you've answered my first comment. Most likely, all the data in your parameters.mat are doubles. Can you answer my comment #3?
in WS all parameters will be double (I don't know why, it's done automatically I think). The ideea is that I want to take the data types directly from the simulink model if it's possible somehow. My parameters in the model are not 'double'. They are int8, uint8, uint16,etc, but not double.
My only solution was to create a xls file with 2 columns: one called : parameter name and the other data type. So I copy paste directly from the model the names and data types and after that it remains only to use xlsread function and take the corresponding data type for each parameter. But this is uncomfortable!!!
I prefer this to be automatically done...
The title of your question is "take the real data type of parameters from the Simulink model". So that is why I keep asking you how do you know a particular parameter in the model is int8 or uint8? Are you asking how to implement a parameter in Simulink model as int8, instead of double?
This is the idea...I don't know what data type has a parameter in Simulink. Only if I look directly in the model... So is there a way to take this data??
I understand your need. But you didn't seem to understand my question. Let's take an example, if you have a Constant block in the model and you set its value to be para1, using the value in the workspace. By default, the data type is double. You could double-click the Constant block, select the Signal Attributes tab, and set the Output data type. There are many options. That's how do you specify the data type in Simulink. My question is, have you done this? If not, every thing is going to be double. There is no need to show it in your GUI. So, my question is still the same. How do you know the data type of a Simulink block output is int8, or uint8, or uint16?
I double click on the corresponding block where I have my parameter and in Signal Atributes tab is the data type of the parameter used... I don't know how to send this data types to workspace in matlab.
See the comment in my answer. DataType=get_param(BlockFullPath,'OutDataTypeStr')

Accedi per commentare.

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.

2 Commenti

Ok!!! This is what I want! Thank you!! Now it's working! Great! You saved my day:)
Another think. Do you know if it's possible to take the name of the parameter used in the block?
CBlks_Name=get_param(CBlks,'Name');
This will return the name of the block, not the name of the variable used in the block.

Accedi per commentare.

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

1 Commento

I could not found nothing to help me to find the names of my used parameters in the Simulink model.(To send these names in matlab workspace)
Only 'OutDataTypeMode' helps me by returning (in Matlab workspace) data types used... but I don't know exactly what parameter has what kind of data type(without looking directly into the model).

Accedi per commentare.

I am using this code for getting all my block types and I see that is not returning also blocks used in my subsystems. It only gives me a list with some blocks that I used in the model, like:'Gain', 'Constant', 'Display', etc and 'SubSystem'.
blks = find_system(gcs, 'Type', 'block'); % Where gcs specifies the currently selected % system or subsystem listblks = get_param(blks, 'BlockType')
Do you know how can I look under these subsystems?To see what i have used there?
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');

Categorie

Tag

Richiesto:

il 15 Set 2011

Community Treasure Hunt

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

Start Hunting!

Translated by