I have a simulink model with a scope output that I want to observe. However, I want the data shown on the previous simulation while being stopped to be continuously shown on the scope window, or saved to a file somewhere. Is there any easy way to achieve this? Thanks in advance.
I'm not sure about showing it on the scope, but you can save the data shown in a scope to a workspace variable, and then save that variable to a mat file.
See the section on Save data to workspace in the scope documentation
Related
I am trying to read values from excel file into different parameters created as flow chart block. Error excelFile cannot be resolved. Steps I have done to import excel:
1- created new experiment.
2- From pallet connectivity imported excel file saved in the same file as model.
3- In experiment window, opened Java action, before each experiment window typed the following code "excelFile.readFile();"
4- into parameter block, Action, on enter delay, typed the following "excelFile.getCellNumericValue("sheet1",5)"
Please see picture for more info
Your "excelFile" object lives on the "Simulation" object, your process blocks are on "Main".
Please learn about object-oriented structures and read the AL help on understanding this: "Where am I and how do I get to..."
In your case, best move the ExcelFile object to Main and access it from there, probably no reason to have it on "Simulation", right?
Also, consider not using ExcelFile at all. Instead, read your excel data into the build-in database and load your params from there. This is how it should be done ;)
I am running Simulink using FastRestart, as I need to start and stop the simulation multiple times changing parameters. When I run Simulink from the main script, there are no problems. However, as soon as I make the script a function so that I can run it for different input data, I get an error that is clearly related to Simulink not seeing the Matlab workspace within the function.
To be more precise, say sfile is my Simulink file, then I run the following lines AFTER having initialized all variables I need in structures in Matlab:
load_system(sfile);
set_param(sfile,'FastRestart','on');
set_param(sfile,'SaveFinalState','on');
set_param(sfile,'SaveCompleteFinalSimState','on');
set_param(sfile,'SimulationCommand','update');
At the last line, I get the error that Simulink does not recognize mdl.tStep (which is the time step), as mdl is not a recognized structure. In fact, it is and if I run Simulink from the main script everything is fine.
Now, in the past, I would have used
options = simset('SrcWorkspace','current');
However, an expert I know has advised me against simset (as it may get deprecated in the future) and encouraged me to use set_param instead. I have
looked up the options for set_param on-line, but I could not find the setting for the Matlab workspace.
Any help would be greatly appreciated. Thank you in advance!
In many instances it is better to use the Model Workspace rather than the Base Workspace:
hws = get_param(model, 'modelworkspace');
hws.assignin('mdl',mdl);
At least be aware that this option exists.
A solution to your problem might be to use the assignin-function to all the variable whose value you want to pass to simulink in your matlab base workspace. To do so just use
assignin('base','mdl',mdl)
Having the variable in your base workspace should allow simulink to see it.
Summary: Is there a way to access user defined variables in vsfi file?
After my simulation is done, in a vsif file, I kick off a post simulation script that will launch Matlab to analyze the output of the DUT.
In order to analyze the data in Matlab I need to compare expected values with observed values. Some of these expected values are defined in my test.e. Is there a way to pass a simulation run variable ( in test.e) to my vsif file?
Thank you
I don't think what you want is possible, as Specman and Vmanager are different tools. Since you're going the post-processing way, you can just dump a text file from your e code that your Matlab script can read.
The .vsif file is descriptive and read at the beginning of the session, so you can't pass information from a task to another task.
I would suggest the same as Tudor.
I have a MATLAB GUI that loads to aid in visually pre-processing data. Essentially it prompts the user to adjust the data range, reduce number of data points, etc... all while providing an updated graph. Upon completion of this work, I want to be able to close out the GUI and pass variables from the GUI to another MATLAB function that does the data analysis. I have found lots of information on how to pass information from a function TO and GUI, but not the other way around.
Any help would be greatly appreciated.
Global variables can cause hard to find bugs. The best solution for your problem (where you want to pass the data directly to another function on close) might be to call the analysis function from the Figure Close Request Function. When the figure your GUI is running in is told to close, it will run the code in this function, which can call your analysis function and have access to the GUI's data.
Matlab GUIs are functions: the code exists in a .m file just like other functions. Like regular functions, they can have return values. You can get as fancy as you want messing with the varargout system, or you can simply return a value, structure, or cell array containing whatever you want. Open up the m-file and edit it to return what you want it to.
Note: If you require special processing when the figure is being closed to generate the appropriate return value, you can reimplement the closeRequestFcn as you see fit.
The easy way: you declare as global variable, where variable stores the data that you want to carry from the GUI to the main MATLAB workspace. Then, you also declare the same global variable on the command window. Hereinafter, variable to be accesible from both scopes, the GUI and the main workspace.
You could also use save or any other alternatives as csvwrite or dlmwrite to store the data into a file, but this doesn't seem to be your case.
I am trying to learn some simple matlab code posted by my professor, and the first line goes somehting like
load /class/mat121/lab1/data
I've never seen "load" used like this before, what does it do? does it load all .m files in the directory?
I also see a lot of custom functions in the code, such as "T()", "Lon()", "Lat()" etc, they aren't standard matlab functions therefore I am assuming they are imported from that directory?
thanks
Title is incorrect, because "data" is not directory.
You can refer to load function.
Anyway,
/class/mat121/lab1/
this should be the directory path
data
this should be a file called "data.mat" which contains matlab workspace variable that is previously saved with save function.
So,
load /class/mat121/lab1/data
loads workspace variables from "data.mat" which is located under "/class/mat121/lab1/".
If you have access to matlab, the best thing to do would be to run the following commands and have a look at the results:
help load
help which
which T
help T
which Lon
which Lat
Running these commands should tell you:
What Load does
What which does
Where T is
What T does
Where Lon is
Where Lat is