Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Command to create a .mat file

Subject: Command to create a .mat file

From: tinne123

Date: 11 May, 2010 20:14:20

Message: 1 of 7

Hi folks,
in R2008b version of Matlab I'd need to use a sort of command to create a new .mat file with a name I choose. Maybe I am blind, but in the documentation I only discovered moves to open and handle an existing .mat file.
Thanks!!

Subject: Command to create a .mat file

From: tinne123

Date: 11 May, 2010 20:25:20

Message: 2 of 7

"tinne123 " <nastanova@yahoo.co.uk> wrote in message <hscdqs$pmf$1@fred.mathworks.com>...
> Hi folks,
> in R2008b version of Matlab I'd need to use a sort of command to create a new .mat file with a name I choose. Maybe I am blind, but in the documentation I only discovered moves to open and handle an existing .mat file.
> Thanks!!

With the above post I mean, I need to implement this in a code (thus asking for a command or function to perform it).

A second problem: I just converted from R2006a to R2008b. I am puzzled by the Matlab Desktop / New and by the File / New menus. It seems to create a new blank .m file which is associated with the Editor. But not a new .mat file. I just tried to close the current workspace. It did, without asking me to save it - what it does in fact is just hiding it and it will return after the tab Current Workspace is chosen again. I just know that in this version, the .mat files are of a database sort, but for the rest I expected they would behave as any other files... Hope someone knows the trick! Thanks!!

Subject: Command to create a .mat file

From: someone

Date: 11 May, 2010 20:43:04

Message: 3 of 7

"tinne123 " <nastanova@yahoo.co.uk> wrote in message <hscefg$75g$1@fred.mathworks.com>...
> "tinne123 " <nastanova@yahoo.co.uk> wrote in message <hscdqs$pmf$1@fred.mathworks.com>...
> > Hi folks,
> > in R2008b version of Matlab I'd need to use a sort of command to create a new .mat file with a name I choose. Maybe I am blind, but in the documentation I only discovered moves to open and handle an existing .mat file.
> > Thanks!!
>
> With the above post I mean, I need to implement this in a code (thus asking for a command or function to perform it).

doc save

% as an example:
save('filename', 'var1', 'var2', ...)
% if filename doesn't have an extension, then .mat is used
>
> A second problem: I just converted from R2006a to R2008b. I am puzzled by the Matlab Desktop / New and by the File / New menus. It seems to create a new blank .m file which is associated with the Editor. But not a new .mat file. I just tried to close the current workspace. It did, without asking me to save it - what it does in fact is just hiding it and it will return after the tab Current Workspace is chosen again. I just know that in this version, the .mat files are of a database sort, but for the rest I expected they would behave as any other files... Hope someone knows the trick! Thanks!!

I'm not sure what "trick" you want.
I think you are right about the *.m vs *.mat files
part, but I don't understand the rest of the above.

Subject: Command to create a .mat file

From: tinne123

Date: 11 May, 2010 21:51:04

Message: 4 of 7

Hey, I am using R2008b the first day, so don't let you irritate by my astonishment. I discovered that now Workspace is living it's own life and instead I need to look on the file pane that is by default on the left, if I want to follow what is happening in .mat files.

Thanks for the tip on save (filename). It seems to create a .mat file in a way... although a bit crazy. I am missing the option to create a blank .mat file through File / New or something like that...

Subject: Command to create a .mat file

From: ImageAnalyst

Date: 11 May, 2010 22:03:57

Message: 5 of 7

And what is the reason for creating a blank/empty .mat file?

Subject: Command to create a .mat file

From: Walter Roberson

Date: 11 May, 2010 22:17:00

Message: 6 of 7

tinne123 wrote:
> I am missing the option to create a blank
> .mat file through File / New or something like that...

There is no documented Mathworks-provided mechanism to create a blank .mat
file from a menu or the command line: the provided mechanisms require that at
least one variable be saved in the .mat file.

I have not looked at the details of the API (Application Programming
Interface). I believe it is possible to make some C / C++ / Fortran / Visual
Basic calls that create a .mat file and then add variables to it, so possibly
it is possible to create a .mat file and then not actually store anything in
it before closing it.

It is not clear to me what the purpose of a blank .mat file would be?

 > I discovered that now Workspace is living it's own life and instead I need
 > to look on the file pane that is by default on the left, if I want to
 > follow what is happening in .mat files.

Ummm, the Workspace pane is an inspector for your in-memory workspace. A .mat
file is not a Workspace -- a Workspace is closer to "all the state and data
associated with a particular function" (though there is also a "global"
workspace accessed by using the 'global' command, and a "base" workspace which
corresponds closely to the state and data associated with command-line
actions.) .mat files are used to hold disk copies of values for later recall.

As the Workspace pane is just a means for you to examine what is happening in
memory, closing the Workspace pane does not do anything other than close the
viewer. There is no reason for the Workspace pane to ask you to save the
values before closing, as the values continue to exist in memory when you are
not looking at them -- no Schrodinger's Cat paradoxes for workspace variables
;-) The Workspace viewer is more or less a debugging tool.

Please note for future reference that the save() command normally *replaces*
the .mat file you name: if you want to add to an existing .mat file, you would
use save() with the '-append' option.

Subject: Command to create a .mat file

From: tinne123

Date: 12 May, 2010 18:07:05

Message: 7 of 7

Thanks for explanation, Walter Roberson, I will try to get used to the nature of .mat files and using the save and related commands.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us