How can I determine the version of a MAT file from MATLAB? - matlab

I am wondering if there is a way to determine whether a particular MAT file is v4, v6, v7 or v7.3?
I am looking for a solution that can determine the version using MATLAB code, preferably without having to load the data into memory.

There is some comment at the beginning of mat-files version 6 or following. This code reads it:
function txt=getMatComment(x)
fid=fopen(x);
txt=char(fread(fid,[1,140],'*char'));
txt=[txt,0];
txt=txt(1:find(txt==0,1,'first')-1);
end
It seems the comment is always 116 chars long, but I did not find any reference. This code reads 140 chars and cuts of at the end.
The part I don't understand: For Version 6 or 7 it says MATLAB 5.0 MAT-file

Related

Getting PottsWheel application for Matlab to create a new model creates an error

I have just installed PottersWheel (latest version) for Matlab (version R2014a) on 64-bit machine. When attempting to use the 'New Model' button I get an error which I have pasted below:
-------------------------------------------
Problem detected at 2014-10-17 14:06:01:
Attempt to reference field of non-structure array.
Line 128 of pwGetFieldWidths.p
Line 170 of pwModel2CellArray.p
Line 126 of pwSaveModel.p
Line 607 of pwCreateModelGUI.p
Line 175 of pwCreateModelGUI.p
Line 95 of gui_mainfcn.m
Line 60 of pwCreateModelGUI.p
Matlab 2014a (mexw64) PottersWheel 3.1.0
-------------------------------------------
Since apparently there is no way to access .p files as they are protected. Does anybody know how to fix this problem?
The .p files are obfuscated MATLAB functions (or kind of object files). So, you cannot edit them. The possibilities are:
You read the documentation carefully, and verify that your arguments obey the requirements;
If #1 fails, you contact the author that holds the source and ask him/her for advice and bug fixing.
If #2 fails, you look for an de-obfucscator/de-compiler.

MATLAB - Warning: Variable 'vol' cannot be saved to a MAT-file whose version is older than 7.3? [duplicate]

This question already has answers here:
issues of saving a large scale matrix to mat file
(2 answers)
Closed 7 years ago.
I have a 800x6 cell array vol, whose 1st to 5th columns are double and 6th column is a 200x200x200 3D double matrix. I am trying to save it to a variable, a .mat file more specifically.
>> save('./vol.mat', 'vol');
Warning: Variable 'vol' cannot be saved to a MAT-file whose version is older than 7.3.
To save this variable, use the -v7.3 switch.
Skipping...
Why is it so? How should I fix it?
P.S.: I feel rather reluctant to save this cell array as a text file, as doing so sort of "destroys" the structure.
I guess this is attributed to the data type you are using. Just try what the error message suggests:
save('./vol.mat', 'vol', '-v7.3')
Version 7.3 of the .mat file format is actually newer than the default version ('-v6'). It has the drawback that it lacks backward compatibility with very old matlab versions, is said to be only available on 64bit systems and is said to be solw. Apart from that I see no reason not to use '-v7.3'.
BTW, I think you can strip the './' and .mat, as these are the defaults, so
save('vol', 'vol', '-v7.3')
should also work (it does so for me in a similar situation).

How to convert a .txt to .cdf ? Needed for Matlab that won't read txt as cdf

I have a txt file that contains data in Common Data Format( CDF ).
Matlab has functions to read this but it does not work. I assume because the extension is .txt and not .cdf.
When I try to read it I get:
??? Error using ==> cdfinfoc
Error issued from CDF library: "NOT_A_CDF_OR_NOT_SUPPORTED: Named CDF is corrupted or
not supported by the current library version."
Error in ==> cdfinfo at 170
tmp = cdfinfoc(filename);
Error in ==> cdfread at 184
info = cdfinfo(filename);
Is there a way to trick Matlab and read it or do I need to transform somehow the txt into a .cdf? If so, how do I do that?
Thank you!
EDIT: The file that I am trying to read is from this link: http://www.ee.washington.edu/research/pstca/pf14/ieee14cdf.txt
This says that the data is in CDF: http://www.ee.washington.edu/research/pstca/pf14/pg_tca14bus.htm
If it's actually a txt file (in that it contains textual data that you can read), then it isn't really in CDF format. You can try makeCDF or some other tool to convert the textual data into a CDF file.
If that doesn't work out for you, you'll need to post more information about the actual format of the file. That text file could contain anything. Maybe provide some example lines?
EDIT
After looking at your file, this is an unrelated format which happens to also be called CDF. You can find a reader for this format here: Read IEEE Common Data Format (CDF) (Power systems, Load Flow)
In both cases I think where it's actually falling over is this call to the library:
fmt = cdflib.getFormat(cdfid);
See: cdflib.getFormat, in particular these lines:
This function corresponds to the CDF library C API routine
CDFgetFormat.
To use this function, you must be familiar with the CDF C interface.
Read the CDF documentation at the CDF Web site.
At any rate it's not due to the file extension alone; I tested this by making a copy of the MATLAB example.cdf, renaming it to example.txt, and calling cdfinfo on both. No errors, returned data is the same except for obvious things like filename/modification date.

Can I force visdiff to display more than the first 2000 bytes?

I have two binary files that I'm trying to compare using Matlab's built-in function visdiff, but it only displays the first 2000 bytes as a default. Is there any way to force the comparison tool to display the entire contents of both files side by side?
Edit the file matlabroot\toolbox\shared\comparisons\private\bindiff.m, where matlabroot is your MATLAB installation directory. On line 149, you'll see it sets the variable MAXLEN to 2000. Change this to something bigger (even Inf seems to work).
You may need to type rehash toolboxcache after making this change, in order to get MATLAB to notice.
Please note:
As you're making a change to the MATLAB source, this is at your own risk (it seems fine to me though). Keep a backup of the file you've edited.
That truncation at 2000 bytes is there for a reason - comparing the whole of larger binary files does seem to take quite a while, so be patient. Maybe try gradually increasing MAXLEN, rather than going straight to Inf.
I only have R2011b available to me right now, so if you're on a newer version the file path and line number I mentioned above may have changed. It was very easy to trace through the code from visdiff to comparisons_private to bindiff though, so unless they've changed the deeper structure of the Comparisons Tool between 11b and now, it will probably be very similar.

Loading a textfile in FreeMat

I am trying to get my MATLAB code for loading and parsing certain text files to work in FreeMat and have run into difficulties on square one.
The file looks like this:
1110000
1001100
1000011
0101010
0100101
0011001
0010110
Number of 7-3-1 designs = 1 Number of designs with |Aut|= 168
is 1
textread.m seems to be unknown to FreeMat and calls to load and dlmread haven't done the job either.
Looks like textscan/textread are not yet implemented in FreeMat. You can instead read the file line-by-line using fgetline (equivalent to fgets in MATLAB).
Here is a list of available IO functions in FreeMat