help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to see all data saved in dat or mat file


From: Ivan Sutoris
Subject: Re: how to see all data saved in dat or mat file
Date: Sat, 11 Oct 2008 10:47:21 +0200

On Sat, Oct 11, 2008 at 9:17 AM, joyce <address@hidden> wrote:
>  hello,
>     I save some results in dat and mat file. While  files are loaded
> successfully,
> I can't see any variable saved in the file and if you don't know which
> varibles are saved in advance, then you can't use the data in file at all.
>  so, is there any command which can help me know what has been saved in
> files
> , like listing all varibles in prompt window.

Hi

if you saved several variables in a file with 'save' command, you can
call 'load' with an output argument, and Octave will return structure
with fields contaning individual variables. Then you can get names of
variables by using 'fieldnames'. For example:

x1 = rand(100,1);
x2 = randn(100,1);
save myfile.dat x1 x2
mydata = load myfile.dat;
myvarnames = fieldnames(mydata);
disp(myvarnames)

Now, mydata.x1 will contain x1 and mydata.x2 will contain x2. Names of
variables are saved as strings in myvarnames, which is a cell array
(so myvarnames{1} is 'x1', myvarnames{2} is 'x2').

> Ps: these dat or mat files are not able to be load in MATLAB?

You can use -v7 option when saving data to save in MATLAB-compatible file:

save -v7 myfile.dat x1 x2

then load it in MATLAB:

load -MAT myfile.dat

Hope this helped
Ivan Sutoris


reply via email to

[Prev in Thread] Current Thread [Next in Thread]