I have a structure with some data in my workspace. This structure has the same format as a bus object already defined.
I want to use this structure in my simulink model.
Is like the use of the "constant" block with scalars but I want to do it with structures.
I found a way (not so nice) which is calling eval of the variable (it's in the workspace) inside a embeded block and outputting that variable but I have problems generating code rtw, , s-functions, etc.
Any ideas? I would really appreciate them, I'm spending to much time with this simple thing, and I'm losing my patience...
Thank you
Raiky
One of those format is a structure, but it is a structure with specific field names and format.
Without knowing the specifics of your model, I'd recommend doing the following,
- use an Inport block
- have some MATLAB code that runs before the model executes (either manually by you or automatically as part of a model initialization callback) that takes your structure and converts it to one listed in the doc above.
- on the Inport block's Signal Attributes tab check the box that says "Specify properties via bus object.
Phill.
so I have my structure str1 (that I want to use inside) and my input var (var1) that I will use in the data import
str1.a = 1
str2.b = 2
str3.c = 3
var1:
var1.time = []
var1.signals(1).values = str
var1.dimensions = 1
It says:
Invalid data values within variable specified as external input in 'untitled'. Data values must neither be Inf nor Nan. Also, the values should be specified using matrices that are neither empty nor sparse.
Should I use MATRICES???
I also try creating a bus with that structure but it says the same.
uff...this is killing me.
Do you have any more idea?
Ramon.
"Phil Goddard" <philgodd...@telus.net> wrote in message <gk5vst$ppa$1...@fred.mathworks.com>...
so I have, my structure str1 (that I want to use inside) and my input var (var1) that I will use
str1.a = 1
str2.b = 2
str3.c = 3
var1:
var1.time = []
var1.signals(1).values = str
var2.dimensions = 1
It says:
Invalid data values within variable specified as external input in 'untitled'. Data values must neither be Inf nor Nan. Also, the values should be specified using matrices that are neither empty nor sparse.
Should I use MATRICES???
I also try creating a bus with that structure but it says the same.
uff...this is killing me.
Do you have any more idea?
Ramon.
"Phil Goddard" <philgodd...@telus.net> wrote in message <gk5vst$ppa$1...@fred.mathworks.com>...
>
The following will work
var1.time = [0 maxreal]';
var1.signals.values = [1 2 3;1 2 3];
var1.dimensions = 3;
The inport block needs to have the Dimension field of its Signal Attrbutes tab set to the same dimensions as the input structure, so in this case 3.
There are several other alternative forms for the structure that will also work.
The concepts/requirements for doing the above is on the documentation page.
Phil
Hi Phil, thanks for your support.
That I realised, it must be an array or matrix. But that is limiting too much, I have an structure which backup a bus information, I cannot changed it to array. . So therefore I cannot use it that way.
I'm wondering why this is not possible as a matlab/simulink functionality, it's not so difficult.
Do you think I have other alternatives? for instance, could I do it by accessing the structure in the workspace from a s-function and outputting it as a bus?
R.
1. Write a function/script that you call manually before running the simulation that converts your data into a matrix format suitable for input to the Inport block.
2. Write a function/scipt that does the above and gets called automatically as part of the model's InitFcn callback.
3. Write an S-function to do the conversion at each time step.
The fact that it can be done as part of an S-Function means that it can be done in m-code, so I find it hard to believe when you say
> ..., I cannot changed it to array. .
You might not want to store it as an array, that's fine, but converting it to one immediately before simulation must be possible.
Phil.
thanks for your help and sorry for not answering anything else yet.
The problem is fixed. I didn't changed anything. The new version of matlab 2008 allows the use of structures as parameters of embedded functions, that's it!
Regards.
Ramon.
"Phil Goddard" <philgodd...@telus.net> wrote in message <gkh4ea$6p4$1...@fred.mathworks.com>...