Read variable values from m-file

I work on a simulation project containing a large simulink model. Before I could load the input variables to the model directly to the base workspace from a large mat-file. For several reasons we had to change the input file format from .mat to .m. The input variables are each stored in one separate m-file. To read the variables to the base workspace I just run the m-files. Each m-file contains one signal name together with the corresponding simulation values in matrix form. Ex: signalA.m; signal_A = [1 3;2 5;....]; The first column is the time stamp values.
My problem is not to read the variables to the workspace but to obtain the stop time value in the signal matrix. I need the last time value in order to activate the simulink model with the correct simulation time from a main function. Before I could just read the last time stamp value from one signal from the mat-file. Does anyone have any idea how to read the signal values from the m-file in order to obtain the last time stamp value?

4 Kommentare

Jan
Jan am 26 Sep. 2011
I do not have an idea. I assume it is impossible to have one without seeing the structure ofthe M-file. Is the signal replied when the function is called?
Storing data in M-files is a extremly inefficient method. Are you really sure that this method reduces the number of problems? Looking at your question, it does not seem so.
Erik
Erik am 26 Sep. 2011
Hi! The m-files are scripts and do not return any values. I know that storing data in m-files is inefficient but this simulation task is just a small part of a much bigger system and I can't influence how the signal data is delivered to the simulation :(. I would of course rather receive one mat-file containing all sigal values! I beleve I just found a way to extract the last time stamp using fopen, fgetl, regexp and finaly convert the output to num. I only have to do this procedure once for each simulation so it won't slow down the system that much :). If anyone has a better idea I'm glad to hear it!
Image Analyst
Image Analyst am 26 Sep. 2011
I don't understand. Don't you have a line in your m-file that says something like
lastStopTime = signal_A(42);
???
Or do you have a scope problem where you need to call assignin(), evalin(), or something like that?
Erik
Erik am 26 Sep. 2011
I'm sorry if I'm confusing. I just realized that I don’t need a simulation time for the simulink model if you have a time vector. :)
Thank you anyway!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Daniel Shub
Daniel Shub am 26 Sep. 2011

0 Stimmen

The problem seems to be that the simulation wants its inputs in terms of many separate m-files, but that it is easier to work with a single data saved in a single mat-file. What about using a mat-file for everything you have control of and writing a wrapper to create the m-files the simulation wants. Just because one stage wants data in an efficient manner, doesn't mean your entire workflow needs to suffer.

Gefragt:

am 26 Sep. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by