Hello all,
I have a Matlab function which imports and uses data from a .mat file. This is held in an array of structures, with each structure holding several elements.
I am trying to convert this function into an embedded Matlab block in a Simulink model.
This block needs to access the data in the .mat file. Ideally, it would load all the data in the .mat file at t=0 and this would persist in memory throughout the simulation.
I've tried to do this in various ways:
- Loading the .mat file directly from within an EML block doesn't work as load() is an extrinsic function, and Matlab is not able to index into/make use of the resulting mxArray.
- Using a constant block in Simulink to import the data doesn't work. It appears to be possible to feed each element of the struct into a separate block and input that to the EML function, but this would mean that only one value per timestep is loaded.
- Using a 'from workspace' block in Simulink doesn't work. This appears to only apply to a vector of values, each of which has a timestep associated with them. This doesn't fit the format of the data I'm using.
- Using a data store and memory block doesn't work as it appears to only load one element of data for each timestep.
None of these options appear to work - does anyone have any suggestions?
thanks
C
|
|
0
|
|
|
|
Reply
|
Calum
|
10/26/2010 6:00:08 PM |
|
"Calum " <cgb7@nonsense.hw.ac.uk> wrote in message <ia74v8$qnn$1@fred.mathworks.com>...
> Hello all,
>
> I have a Matlab function which imports and uses data from a .mat file. This is held in an array of structures, with each structure holding several elements.
> I am trying to convert this function into an embedded Matlab block in a Simulink model.
> This block needs to access the data in the .mat file. Ideally, it would load all the data in the .mat file at t=0 and this would persist in memory throughout the simulation.
> I've tried to do this in various ways:
>
> - Loading the .mat file directly from within an EML block doesn't work as load() is an extrinsic function, and Matlab is not able to index into/make use of the resulting mxArray.
> - Using a constant block in Simulink to import the data doesn't work. It appears to be possible to feed each element of the struct into a separate block and input that to the EML function, but this would mean that only one value per timestep is loaded.
> - Using a 'from workspace' block in Simulink doesn't work. This appears to only apply to a vector of values, each of which has a timestep associated with them. This doesn't fit the format of the data I'm using.
> - Using a data store and memory block doesn't work as it appears to only load one element of data for each timestep.
>
> None of these options appear to work - does anyone have any suggestions?
>
> thanks
> C
You can do this using a callback:
1) Open your Simulink model
2) Click "File" -> "Model Properties"
-3) Select the second tab, called "Callbacks" in the "Model Properties" window that opened up
4) Select the right callback, and type in the name of your MATLAB function.
You probably can use "PreLoadFcn" callback. The in the "Model pre-load function:" part of the window, type your function, i.e., type loaddata if your function is loaddata.m.
Here is the doc reference:
http://www.mathworks.com/help/toolbox/simulink/ug/f4-122589.html
HTH.
Arkadiy
|
|
0
|
|
|
|
Reply
|
Arkadiy
|
10/27/2010 3:28:05 PM
|
|
"Arkadiy Turevskiy" <arkadiy.turevskiy@mathworks.com> wrote in message <ia9ge5$dli$1@fred.mathworks.com>...
> "Calum " <cgb7@nonsense.hw.ac.uk> wrote in message <ia74v8$qnn$1@fred.mathworks.com>...
> > Hello all,
> >
> > I have a Matlab function which imports and uses data from a .mat file. This is held in an array of structures, with each structure holding several elements.
> > I am trying to convert this function into an embedded Matlab block in a Simulink model.
> > This block needs to access the data in the .mat file. Ideally, it would load all the data in the .mat file at t=0 and this would persist in memory throughout the simulation.
> > I've tried to do this in various ways:
> >
> > - Loading the .mat file directly from within an EML block doesn't work as load() is an extrinsic function, and Matlab is not able to index into/make use of the resulting mxArray.
> > - Using a constant block in Simulink to import the data doesn't work. It appears to be possible to feed each element of the struct into a separate block and input that to the EML function, but this would mean that only one value per timestep is loaded.
> > - Using a 'from workspace' block in Simulink doesn't work. This appears to only apply to a vector of values, each of which has a timestep associated with them. This doesn't fit the format of the data I'm using.
> > - Using a data store and memory block doesn't work as it appears to only load one element of data for each timestep.
> >
> > None of these options appear to work - does anyone have any suggestions?
> >
> > thanks
> > C
>
> You can do this using a callback:
> 1) Open your Simulink model
> 2) Click "File" -> "Model Properties"
> -3) Select the second tab, called "Callbacks" in the "Model Properties" window that opened up
> 4) Select the right callback, and type in the name of your MATLAB function.
> You probably can use "PreLoadFcn" callback. The in the "Model pre-load function:" part of the window, type your function, i.e., type loaddata if your function is loaddata.m.
>
> Here is the doc reference:
> http://www.mathworks.com/help/toolbox/simulink/ug/f4-122589.html
>
> HTH.
> Arkadiy
Thanks, that seems to do the trick.
C
|
|
0
|
|
|
|
Reply
|
Calum
|
11/2/2010 8:48:04 AM
|
|
|
2 Replies
1072 Views
(page loaded in 0.042 seconds)
Similiar Articles: Load data/.mat-file in Simulink - comp.soft-sys.matlabHello all, I have a Matlab function which imports and uses data from a .mat file. This is held in an array of structures, with each structure holdi... load matrix from workspace to simulink - comp.soft-sys.matlab ...Load data/.mat-file in Simulink - comp.soft-sys.matlab load matrix from workspace to simulink - comp.soft-sys.matlab ... Load data/.mat-file in Simulink - comp.soft ... load/use image in Simulink - comp.soft-sys.matlabLoad data/.mat-file in Simulink - comp.soft-sys.matlab load/use image in Simulink - comp.soft-sys.matlab As an example, I am aware I can read a bitmap image in ... values ... Load mat-file from GUI - comp.soft-sys.matlabLoad data/.mat-file in Simulink - comp.soft-sys.matlab Newsreader - MATLAB Central to controll 2 PId controller: Thread: FIS built in GUI: Thread: Problem with PID Tuner ... Using data structures in Simulink - comp.soft-sys.matlab ...Load data/.mat-file in Simulink - comp.soft-sys.matlab This is held in an array of structures, with each structure ... > > - Using a constant block in Simulink to import ... Saving/Loading The Workspace From a Structure Within .mat - comp ...Load data/.mat-file in Simulink - comp.soft-sys.matlab Saving/Loading The Workspace From a Structure Within .mat - comp ... Saving/Loading The Workspace From a Structure ... change 'file name' in 'From Multimedia File' simulink block - comp ...I need to load a avi video into workspace and do some processing work. I use the 'From Multimedia File' block in simulink to extract the audio of the ... Capture JPEG images using Simulink - comp.soft-sys.matlab ...load/use image in Simulink - comp.soft-sys.matlab Capture JPEG images using Simulink - comp.soft-sys.matlab ... Load data/.mat-file in Simulink - comp.soft-sys.matlab ... Matlab and Simulink Data Input as bit stream - comp.soft-sys ...Load data/.mat-file in Simulink - comp.soft-sys.matlab Load data/.mat-file in Simulink - comp.soft-sys.matlab Matlab and Simulink Data Input as bit stream - comp.soft-sys ... How to Import data independent of time to a Simulink Model? - comp ...Load data/.mat-file in Simulink - comp.soft-sys.matlab... block in a Simulink model. This block needs to access the data in ... block in Simulink to import the data doesn ... Load data/.mat-file in Simulink - Newsreader - MATLAB CentralFile exchange, MATLAB Answers, newsgroup access, Links, and Blogs for the MATLAB & Simulink user community Read data from MAT-file - Simulink - MathWorks - MATLAB and ...For each simulation time hit for which the MAT-file contains no matching time stamp, Simulink ... load('my_data_file.mat') save('my_data_file.mat', 'var', '-v7.3') ... 7/20/2012 8:48:23 PM
|