How to load data from Octave?

152 views (last 30 days)
Svit
Svit on 13 Feb 2026 at 14:32
Edited: dpb 40 minutes ago
I have a .M file from Octave that I want to run in MATLAB, but I obtain an error. Here is the content of .M file (it's just one line):
load "Slovenia_centered.mat"
And here is the error:
Error using load
Unable to read file '"Slovenia_centered.mat"': Invalid argument.
Error in
Slovenia_centered (line 1)
load "Slovenia_centered.mat"
^^^^

Accepted Answer

dpb
dpb on 13 Feb 2026 at 16:06
Edited: dpb on 13 Feb 2026 at 22:15
d=dir('Slovenia_centered.mat')
d = struct with fields:
name: 'Slovenia_centered.mat' folder: '/users/mss.system.hwgbc' date: '13-Feb-2026 16:09:15' bytes: 8972 isdir: 0 datenum: 7.4003e+05
type Slovenia_centered.mat
2.43585211e-01 4.34165188e-02 -1.12349916e-01 -2.28456591e-01 -1.91116589e-01 -2.70689717e-01 -3.11419208e-01 -3.50257617e-01 -6.65425832e-02 -9.14570313e-03 -8.20596965e-02 -1.78167486e-01 -2.97052722e-01 -2.46918797e-01 -2.19440188e-01 -2.70686443e-01 -3.18241940e-01 -2.10150356e-01 -2.13653827e-01 -2.17390732e-01 -2.62264223e-01 -1.49604529e-01 -1.09957459e-01 -9.49376074e-02 -1.24863682e-01 -3.15208845e-02 -8.90212675e-02 -3.55029042e-02 -8.28967479e-02 -1.76605387e-02 -2.30428121e-02 1.34293699e-03 -4.54977381e-02 6.45433851e-02 4.78045373e-02 7.24064017e-02 6.99667015e-03 9.52555827e-02 7.73363149e-02 8.51807013e-02 1.02811162e-02 1.13232188e-01 1.01257891e-01 8.56573993e-02 2.88423567e-03 9.61062203e-02 9.35117925e-02 8.53008908e-02 4.38889826e-04 1.25063364e-01 8.51262928e-02 7.02835862e-02 -1.06633213e-02 9.41939577e-02 7.82578294e-02 6.40646937e-02 2.02679656e-02 1.20137869e-01 1.24714671e-01 7.65958761e-02 3.86603250e-02 1.23444122e-01 1.21628133e-01 6.84510581e-02 -2.90423111e-02 4.92981441e-02 8.13086803e-02 4.57275391e-02 -4.60431416e-02 4.40207933e-02 7.70448326e-02 4.76952588e-02 -4.70176957e-02 5.09027753e-02 8.21718603e-02 5.11014038e-02 -3.14864492e-02 2.94709272e-02 5.25549402e-02 5.06473681e-02 -5.70459574e-02 2.85747947e-02 6.58264244e-02 8.00351937e-02 -1.53487772e-02 5.07730799e-02 8.77231592e-02 8.00775769e-02 -2.01877342e-03 7.10339434e-02 9.95038228e-02 8.51411552e-02 1.12622263e-02 7.48661734e-02 1.25845338e-01 1.13047672e-01 6.44208366e-03 8.20784658e-02 1.15861587e-01 1.16981801e-01 1.32878713e-02 8.13856501e-02 1.25175055e-01 1.33878725e-01 -1.98675542e-03 7.90652670e-02 1.35774710e-01 1.08919874e-01 -7.07711107e-02 8.92207774e-02 -4.65527936e-02 -1.57130551e-01 -2.40994223e-01 -4.96244659e-02 -1.52453018e-01 -2.12563368e-01 -2.67801452e-01 4.95756179e-02 -4.40686368e-02 -1.15580766e-01 -1.25775054e-01 -1.73384135e-01 -1.52179917e-01 -1.43851209e-01 -2.10410045e-01 -1.97070525e-01 -1.41407124e-01 -1.27659408e-01 -1.55943094e-01 -1.35964420e-01 -1.31516033e-01 -1.19209025e-01 -8.49613192e-02 -6.95622210e-02 4.68736421e-02 -1.26130498e-01 -6.93363832e-02 -5.69920136e-02 -6.40601175e-02 -3.47545081e-02 -2.75506476e-02 -3.69073157e-02 -2.91088444e-02 6.72125124e-03 -1.48267606e-02 -4.09041711e-02 -2.43471523e-02 -1.06314026e-02 2.90942493e-02 1.06398348e-02 5.28797535e-02 5.81501672e-02 6.46773605e-02 7.99001652e-02 5.88197546e-02 9.74155904e-02 6.80675013e-02 3.69971704e-02 7.15738061e-02 4.92185352e-02 8.51880605e-02 5.25690589e-02 4.70319887e-02 8.73093630e-02 1.24347841e-01 8.34957748e-02 8.01157151e-02 1.04087442e-01 5.52314058e-02 1.03144746e-01 8.71002361e-02 8.58075469e-02 -3.39072211e-02 -1.60503962e-01 -1.63662056e-01 -1.32633635e-01 -1.58251994e-01 -1.91495362e-01 -1.29823541e-01 -9.37579206e-02 -5.39783749e-02 -3.68312926e-02 -2.66630432e-02 3.32789371e-03 3.26337438e-02 1.01304451e-02 2.23581354e-02 5.22598442e-02 4.47007363e-02 1.19954623e-01 1.03389332e-01 1.06359929e-01 1.46719725e-01 1.30101143e-01 1.12428279e-01 1.30705523e-01 8.45389663e-02 1.08088593e-01 9.75684648e-02 1.01395119e-01 9.71937745e-02 3.47484905e-02 4.42750299e-02 8.25424161e-02 9.21584290e-02 1.13038218e-01 1.19697351e-01 1.14179812e-01 1.44723437e-01 1.28270457e-01 1.21420846e-01 1.45170111e-01 1.37681317e-01 1.21213960e-01 9.30495370e-02 7.33983930e-02 2.96409051e-02 8.40368523e-03 1.53894823e-01 1.16035111e-01 5.81934066e-02 1.08556223e-02 4.86781106e-02 -1.05331625e-02 -3.43596071e-02 -7.51130657e-02 -1.00049299e-01 -1.14882779e-01 -1.45116531e-01 -1.57761801e-01 -1.83074680e-01 -1.80367065e-01 -1.54923112e-01 -1.84838759e-01 -2.11886923e-01 -1.99723197e-01 -1.58956814e-01 -1.51969260e-01 -1.50441005e-01 -1.04679706e-01 -9.98488344e-02 -9.69258753e-02 -7.92101973e-02 -6.23525044e-02 -9.78704987e-02 -7.80931130e-02 -7.38248638e-02 -3.76943507e-02 -4.05711033e-02 -2.24749292e-02 -1.46918983e-02 3.47575728e-02 3.09042411e-02 6.48459274e-02 6.48847362e-02 6.39247697e-02 5.58703001e-02 8.41531535e-02 4.15551778e-02 3.08979935e-02 3.04199093e-02 1.50047061e-02 -1.43383975e-02 -2.64013521e-02 -1.13675746e-02 -1.78031382e-02 -2.24706655e-02 -1.23830497e-01 -1.52337276e-01 -1.02269500e-01 -7.09244756e-02 -5.14008250e-02 -2.04815280e-02 3.98515553e-03 -9.94963306e-03 5.81655913e-04 6.20384609e-02 3.66873561e-02 4.44709790e-02 3.01924135e-02 7.34990120e-02 1.01999638e-01 8.96974405e-02 8.91687653e-02 8.25398823e-02 5.87013493e-02 4.75817750e-02 3.78256882e-02 5.58710325e-02 3.69790976e-02 2.76071724e-02 2.99780538e-02 4.58801499e-02 4.09223762e-02 3.63845571e-02 3.68050568e-02 2.64511191e-02 2.18297644e-02 1.92599831e-02 9.93448050e-03 1.63902029e-02 1.54940734e-02 2.20701954e-02 2.61649928e-02 6.15279108e-02 5.35505614e-02 5.06709261e-02 4.76384299e-02 6.49500327e-02 5.76095342e-02 7.29864361e-02 5.68674368e-02 8.22899297e-02 7.86909945e-02 7.71742431e-02 7.29094161e-02 7.81446248e-02 6.99662839e-02 7.20843451e-02 6.40103939e-02 7.74977970e-02 7.01916143e-02 6.66090971e-02 5.74273222e-02 7.55973754e-02 5.82662735e-02 4.72813797e-02 2.64495060e+01 1.12540703e+01 1.20777772e+01 2.28580935e+01 1.38260053e+01 1.31007766e+01 1.10022506e+01 1.66790277e+01 8.22458464e+00 -2.49031719e-01 5.29807266e-01 5.65329456e+00 6.25817197e+00 8.02464904e+00 3.49623740e+00 5.45883295e-01 2.39698471e+00 3.14655001e+00 4.34955656e+00 4.77493419e+00 5.03013884e+00 4.89452079e+00 2.62649397e+00 9.42308053e-01 1.09752442e+00 -2.52475578e-01 9.60857755e-01 2.62752442e+00 3.61085776e+00 4.03085776e+00 3.93085776e+00 3.93085776e+00 3.70419109e+00 4.02419109e+00 3.91085776e+00 2.20752442e+00 2.62752442e+00 3.29085776e+00 3.45752442e+00 2.02419109e+00 2.40419109e+00 1.65419109e+00 1.29419109e+00 1.07085776e+00 6.34191089e-01 -4.39142245e-01 -1.13914224e+00 -1.10580891e+00 -1.12580891e+00 -1.12580891e+00 -1.14580891e+00 -1.16914224e+00 -1.38580891e+00 -1.71580891e+00 -1.70580891e+00 -1.57247558e+00 -1.35547558e+00 -1.11097558e+00 -6.75308911e-01 -4.51042245e-01 -6.95808911e-01 -3.15342245e-01 -1.94008911e-01 -9.61142245e-01 -3.16410891e+00 -3.86517558e+00 -4.30660891e+00 -4.45390891e+00 -4.51367558e+00 -4.48954224e+00 -4.30087558e+00 -4.15534224e+00 -4.08267558e+00 -3.76417558e+00 -3.61374224e+00 -3.68024224e+00 -4.13280891e+00 -4.47977558e+00 -4.81724224e+00 -4.98067558e+00 -4.96434224e+00 -4.96900891e+00 -4.95230891e+00 -4.93490891e+00 -4.88067558e+00 -4.87724224e+00 -5.01124224e+00 -5.09434224e+00 -5.12977558e+00 -5.18234224e+00 -5.20360891e+00 -5.26497558e+00 -5.36187558e+00 -5.43390891e+00 -5.47390891e+00 -5.48830891e+00 -5.50360891e+00 -5.50577558e+00 -5.50544224e+00 -5.50460891e+00 -5.50410891e+00 -5.50104224e+00 -5.49530891e+00 -5.49114224e+00 -5.48434224e+00 -5.49290891e+00 -5.57254224e+00 -5.57877558e+00 -5.58130891e+00 5.46880734e-02 2.66880734e-02 2.96880734e-02 4.76880734e-02 2.66880734e-02 3.46880734e-02 2.46880734e-02 3.36880734e-02 1.26880734e-02 -3.11926606e-04 8.68807339e-03 1.26880734e-02 1.96880734e-02 1.06880734e-02 -1.13119266e-02 9.68807339e-03 1.26880734e-02 1.66880734e-02 -3.11926606e-04 6.68807339e-03 1.76880734e-02 5.68807339e-03 -9.31192661e-03 -3.11926606e-04 4.68807339e-03 -3.31192661e-03 1.96880734e-02 6.68807339e-03 1.36880734e-02 4.68807339e-03 1.26880734e-02 5.68807339e-03 1.46880734e-02 1.16880734e-02 -1.31192661e-03 -6.31192661e-03 1.96880734e-02 4.68807339e-03 2.68807339e-03 -6.31192661e-03 1.26880734e-02 3.68807339e-03 -8.31192661e-03 -9.31192661e-03 6.88073394e-04 6.68807339e-03 -1.43119266e-02 -1.03119266e-02 6.88073394e-04 -8.31192661e-03 6.88073394e-04 -1.73119266e-02 -5.31192661e-03 2.68807339e-03 -5.31192661e-03 -1.23119266e-02 -7.31192661e-03 1.26880734e-02 -8.31192661e-03 7.68807339e-03 6.88073394e-04 1.56880734e-02 -1.93119266e-02 -2.83119266e-02 -1.31192661e-03 6.88073394e-04 -2.03119266e-02 -7.31192661e-03 -5.31192661e-03 4.68807339e-03 -2.13119266e-02 -7.31192661e-03 -2.31192661e-03 -4.31192661e-03 -1.43119266e-02 -7.31192661e-03 6.88073394e-04 -3.31192661e-03 -2.31192661e-03 -1.33119266e-02 -7.31192661e-03 -3.31192661e-03 -8.31192661e-03 -1.93119266e-02 -1.13119266e-02 6.88073394e-04 -2.03119266e-02 -1.93119266e-02 -1.33119266e-02 -5.31192661e-03 -2.03119266e-02 -1.43119266e-02 -1.83119266e-02 3.68807339e-03 -1.93119266e-02 -1.13119266e-02 -3.31192661e-03 -6.31192661e-03 -1.43119266e-02 -5.31192661e-03 -8.31192661e-03 1.68807339e-03 -1.53119266e-02 -1.33119266e-02 -7.31192661e-03 5.68807339e-03 -1.63119266e-02 -1.23119266e-02 -1.93119266e-02
Aha! It's text, not native .mat.
x=load('-ascii','Slovenia_centered.mat')
x = 545×1
0.2436 0.0434 -0.1123 -0.2285 -0.1911 -0.2707 -0.3114 -0.3503 -0.0665 -0.0091 -0.0821 -0.1782 -0.2971 -0.2469 -0.2194
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
To write data from Octave to be imported into MATLAB, it would be more portable to either explicitly write text data with fprintf or whatever other higher-level functions Octave has implemented in parallel with MATLAB or as native binary data with fwrite to read with fopen and fread
Although, presuming Octave has it implemented, if it can write a specific version of a .mat file that has the benefit of also storing the variables and shape and type information that alternate forms don't without extra effort. Just have to be sure to write in a known version and then verify it does work as expected (not that I have any reason to think it wouldn't; Octave has been around for a long time).
  8 Comments
Stephen23
Stephen23 21 minutes ago
Edited: Stephen23 20 minutes ago
If you require that single quote after the integer:
'Vector length (%d'') not compatible; unable mae to 5 variables. Aborting.'
% ^^
Otherwise:
'Vector length (%d) not compatible; unable mae to 5 variables. Aborting.'
dpb
dpb about 4 hours ago
Edited: dpb 40 minutes ago
Problem with trying to edit inline in the forum without syntax checking in place...changed horses in mid-stream about adding the message in the assert call to separate catch clause and didn't catch all the fixups needed including the dangling quote.
What I really intended was something more on the order of
error('Vector length (%d) not compatible; unable reshape to 5 variables. Aborting.', ...
numel(Slovenia_centered))
There was also a leftover ",5"" from the initial mod() operation pasted in plus a typo in the error message text itself.
"...now I plan to use MATLAB only."
You'll probably find that a good decision in the long run.
I'll note in doing so that earlier you mentioned "demeaning (deducting means) for all 5 variables: Dataslrobs=center(Dataslrobs) (repeating this five times for all 5 variables) ".. Note that in MATLAB (and Octave, too, for that matter) virtually all builtin functions operate by column so it isn't necessary to either loop or duplicate variable names in such a fashion; it's a general sign of not using the vector ability of MATLAB effectively. Instead, use arrays and if need to identify columns in the array, use the table or named fields in a structure; these can be easily manipulated programmatically with direct code to address them rather than having to use contorted features such as eval or duplicate code lines multiple times to operate on the data. Although MATLAB does not explicitly incorporate the center function, it uses
s_c=detrend(s,0); % remove best 0-order trend from array s by column
The above is identical to
s_c=s=mean(s);
and, of course, if the mean isn't of interest, one can always just replace the original data in place and if wanted, keep the means in another array.
m=mean(s); % compute means of s
s=s-m; % remove means, keeping their values if want later
Of course, one could add their own(*) center function via a user m-file or via an anonymous function...
center=@(a)a-mean(a); % anon function center
although one can't support the optional dim argument that way.
(*) As a personal use pattern, besides a default Work directory I create an Utilities folder in which I keep such generally useful functions that aren't (yet) built into MATLAB. I permanently add these two folers at the top if the MATLAB path so anything in Work, then Utilities is called first.
If I have a specific piece of work for a given client or job, I create its own folder and have a pattern for setting a work environment that will save the current default path and then move to the other environment incorporating any other specific pieces needed for it. These uniformly also rely on the Utilites being available. I can then use the optional input parameter with a value of 'quit' to exit that location and return to the base Work location. That has been most helpful working model to keep things localized but have a common toolset available regardless.

Sign in to comment.

More Answers (1)

dpb
dpb on 13 Feb 2026 at 14:50
load "Slovenia_centered.mat"
Using the command syntax the filename is text already so it's including the apostrophes as well...try
load Slovenia_centered.mat
I'm not sure about what level for .mat file compatibility Octave supports, you may need to check there about ensuring .mat files.
  3 Comments
dpb
dpb on 13 Feb 2026 at 15:22
BTW, to complete the picture
load("Slovenia_centered.mat")
will also work because as an argument the "" are constructors and the underlying char string will be passed.
Stephen23
Stephen23 on 13 Feb 2026 at 15:44
According to the Octave SAVE documentation
its default is to "Save the data in Octave’s text data format. (default)." Apparently it also has options to save in formats which are MATLAB compatible.

Sign in to comment.

Tags

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!