Matlab data is in files with extension mat.
Embed mat file in m file.
Name of file specified as a character vector or string scalar.
The data is a sequence of samples.
If you don t want to run the whole m file you can just copy the part of the m file that you want to run and paste it at the matlab prompt.
So you want a function that when given the name of a mat file will create an m file.
I m answering assuming that you are mentioning mat file.
Matlab allows writing two kinds of program files scripts script files are program files with m extension.
Sean de wolski on 21 jun 2012.
For example here i am saving the m file with the naming dipslab m.
Extension of the new matlab file should be mat or m file.
Matlab also allows you to write series of commands into a file and execute the file as complete unit like writing a function and calling it.
If you do not specify filename the load function searches for a file named matlab mat.
Sample mat file program example write a matlab program to solve the mathematical calculation for example the addition of two numbers calculate the value of a.
The from file block loads data from a mat file into a model and outputs the data as a signal.
But if your matlab code just contains variable assignments yes then you can convert assuming you have a file testm m with the assigments.
M file is merely a matlab script file if the data you want to load has regular name like name1 mat name2 mat i recommend you to use eval function with for loop.
If filename has no extension that is no text after a period load looks for a file named filename mat if filename has an extension other than mat the load function treats.
In these files you write series of commands which you want to execute.
The from file block icon shows the name of the mat file that supplies the data to the block.
Thus you can t always convert.
The data can be in array format or matlab timeseries format.
Filename can include a file extension and a full or partial path.
Each sample consists of a time stamp and an associated data value.