unable to save a workspace variable in matlab - matlab

while trying to save a workspace variable it throws an error in matlab saying I need to switch to -v7.3. I am not sure how to resolve this error since the earlier versions dont support readtable function or xlsread function for an excel file.

You simply need to use one of these:
save('file.m','var1','var2',-v7.3);
save file.m var1 var2 -v7.3
Matlab will save data by default to an older format of .mat files. This format does not support variables larger than 2^31 bytes but can be read by old releases of Matlab (pre-R2006b). If you have large variables, you need to switch to format 7.3.
All of this is in the documentation from the save function. Type doc save and read.

Related

Can't save plot as png file ( Error using hgexport)

I'm trying to save a plot as png (i.e. other formats suffer from this problem) via save as but I got this error
Error using hgexport
Error using print
Too many input arguments
Any suggestions? Matlab R2016a
After using which print, it seems there is a user-defined function whose name is print in this folder
C:\Users\XXXX\Documents\MATLAB\print.m
Matlab is probably trying to call this function instead of the one which is defined in here
C:\Program Files\MATLAB\R2016a\toolbox\matlab\graphics\print.m
This is really awkward. Matlab should alter users when they name functions with already built-in functions. After renaming the user-defined function, Matlab successfully saved the figure as png.

Convert dataset of .mat format to .csv octave/matlab

there are datasets in .mat format in the this site: http://www.cs.nyu.edu/~roweis/data.html
I want to change the format to .csv.
Can someone tell me how to change the format to create the .csv file.
Thanks!
Suppose that the .mat files from the site are available already. In the command window in Matlab, you may write, for example:
load('C:\Users\YourUserName\Downloads\mnist_all.mat');
to load the .mat file; the result should be a set of matrices test0, test1, ..., train0, train1 ... created in your workspace, which you want saved as CSV files. Because they're different size, you need to save one CSV per variable, e.g. (also in the command window):
csvwrite('C:\Users\YourUserName\Downloads\mnist_test0.csv', test0);
Repeat the command for each variable, and do not forget to change also the name of the output file to avoid overwriting.
Did you tried the csvwrite function in Matlab?
Just load your .mat files with the load function and then write them with csvwrite!
I do not have a Matlab license so I installed GNU Octave 4.2.1 (2017) on Windows 10 (thank you to John W. Eaton and others). I was not fully successful using the csvwrite so I used the following workaround. (BTW, I am totally incompetent in the Octave world. csvwrite worked for simple data structures).
In the Command Window I used the following two commands
load myfile.mat
save("-text","myfile.txt","variablename")
When the "myfile.mat" is loaded, the variable names for the data vectors loaded are displayed in the workspace window. This is the name(s) to use in the save command. Some .mat files will load several data structures.
The "-text" option is the default, so you may not need to include this option in the command.
The output file lists the .mat file contents in text format as single column (of potentially sequential variables). It should be easy to use you text editor to massage this data into the original matrix structure for use in whatever app you are comfortable with.
Had a similar issue. Needed to convert a series of .mat files that had two columns of numerical data into standard data files (ascii text). Note that I don't really ever use csv, but everything here could be adapted by using csvwrite instead of the standard save.
Using Octave 4.2.1 ....
load myfile.mat
LI = [L, I] ## L and I are column vectors representing my data
save myfile.txt LI
Note that L and I appear to be default variable names chosen by Octave for the two columns vectors in my original data file. Ideally a script that iterated over all files with the .mat extension in my directory would be ideal, but this got the job done. It saves the data as two space separated columns of data.
*** Update
The following script works on Octave 4.2.1 for a series of data files with the .mat extension that are in the same directory. It will iterate over them and write the data out to text files with the same name but with the extension .dat . Note that this is not efficient, so if you have a lot of files or if they are large it can take a while to run. I would suggest that you run it from the command line using octave mat2dat.m so you can actually watch it go.
I make no guarantees that this will work for you, but it did for me. I also am NOT proficient in Octave or Matlab, so I'm sure a better solution exists.
# mat2dat.m
dirlist = glob("*.mat")
for i=1:length(dirlist)
filename = dirlist{i,1}
load(filename, "L", "I")
LI = [L,I]
tmpname = filename(1:length(filename)-3)
txtname = strcat(tmpname, 'dat')
save(txtname, "LI")
end

Cannot save really big matrix in Matlab

I have a big array (1024x1024x360) and I want to save it to a mat file. When I just try
A=rand(1024,1024,360)
save('filename.mat','A');
The variable is created in the workspace, the file is being created, but it remains empty...
I'm using Matlab 2012a on Win7-64 machine, Why is that happening?
Earlier versions of Matlab couldn't save variables larger than 2 GB. Your default save file format may be set to an older type even on newer versions of Matlab; my own install of R2013a seems to have come preset to v7, which won't save anything that big. You have two choices: either specify the format for this file using an extra flag:
save('filename.mat','A','-v7.3');
or change the default for all save files by running preferences and looking in the MAT-files area under General.

Extract .mat data without matlab - tried scilab unsuccessfully

I've downloaded a data set that I am interested in. However, it is in .mat format and I do not have access to Matlab.
I've done some googling and it says I can open it in SciLab.
I tried a few things, but I haven't found any good tutorials on this.
I did
fd = matfile_open("file.mat")
matfile_listvar(fd)
and that prints out the filename without the extension. I tried
var1 = matfile_varreadnext(fd)
and that just gives me "var1 = "
I don't really know how the data is organized. The repository described the data it contains, but not how it is organized.
So, my question is, what am I doing wrong in extracting/viewing this data? I'm not committed to SciLab, if there is a better tool for this I am open to that.
One options is to use Octave, which can read .mat files and run most Matlab .m files. Octave is open source with binaries available for Linux, Mac, and Windows. Inside of Octave you can load the file using:
load file
See Octave's manual section 14.1.3 Simple File I/O for more details.
In Scilab:
loadmatfile('file.mat');
(Source)
I had this same interest a few years back. I used this question as a guide. It uses Python and SciPy. There are options for NumPy and hd5f as well. Another option is to write your own reader for the .mat format in whatever language you need. Here is the link to the mat file format definition.

issues of saving a large scale matrix to mat file

I was trying to save a matrix into a mat file, but the Matlab returns the following messages:
Warning: Variable 'listmatrix' cannot be saved to a MAT-file whose version is older than 7.3.
To save this variable, use the -v7.3 switch.
Skipping...
What does it mean for "use the -v7.3 switch"?
Should I use
save testresult.mat -v7.3 listmatrix
or sth else?
Hi i thought I’d reply to this thread as I’ve been trying to figure out how to save a large (>2 GB) .mat file in matlab v7 (v7.1.0.183) (R14) and finally found a solution.
If you try to use the save command you will get the following error:
save('test.mat', 'data');
Warning: Variable 'data' cannot be saved to a MAT-file because its
storage requirements exceed 2^31 bytes. This limitation will be
addressed in a future release. Consider storing this variable in HDF5
file format (see HDF5WRITE). Skipping...
The solution is to write a HDF5 file instead:
hdf5write('test.hdf5', '/dataset1', data);
You can then read the data back into matlab using:
hdf5read('test.hdf5', '/dataset1');
A quick google search says yes. Try
save -v7.3 testresult.mat listmatrix
How big is your object? (Do whos listmatrix)
You could potentially save memory by using different data type such as uint8.
http://www.mathworks.ch/matlabcentral/newsreader/view_thread/243327
http://www.mathworks.de/matlabcentral/newsreader/view_thread/307845