How to load data from Octave?

54 ビュー (過去 30 日間)
Svit
Svit 2026 年 2 月 13 日 14:32
編集済み: dpb 約20時間 前
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"
^^^^

採用された回答

dpb
dpb 2026 年 2 月 13 日 16:06
編集済み: dpb 2026 年 2 月 13 日 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).
  2 件のコメント
Svit
Svit 約16時間 前
移動済み: dpb 約16時間 前
Thank you so much dpb. One further question. I need the data not in one column, but in five columns, such as in the attached file Slovenia. The data include observations of five variables: consumption, investment, interest rates, inflation rate and monetary aggregate M3. How could I split the data in multiple columns? I searched the questions on this forum, as well as on Google and AI (Copilot), but I haven't found anything useful.
My code looks like this, it includes temp variable that includes five types of data:
temp = [ data];
Dataslpiobs=temp(:,1);
Dataslinobs=temp(:,2);
Dataslcobs=temp(:,3);
Dataslrobs=temp(:,4);
Dataslmobs=temp(:,5);
Your help is much appreaciated!
dpb
dpb 約15時間 前
編集済み: dpb 約15時間 前
I moved to continue the same thread -- dpb
That depends on how the data were written...let's see what the file actually contains...
%type Slovenia
Slovenia
whos
Name Size Bytes Class Attributes Dataslcobs 109x1 872 double Dataslinobs 109x1 872 double Dataslmobs 109x1 872 double Dataslpiobs 109x1 872 double Dataslrobs 109x1 872 double ans 1x34 68 char temp 109x5 4360 double
Well, we have five variables each of whch is a vector and another that is an array of the composite size of the others...one presumes that was created from them?
OK, now see what was mentioned in the comment...
vnames={'Dataslcobs','Dataslinobs','Dataslmobs','Dataslpiobs','Dataslrobs'};
tData=array2table(temp,'VariableNames',vnames);
head(tData)
Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs __________ ___________ __________ ___________ __________ 0.067 0.037379 0.18434 31.625 0.11012 0.039 -0.098394 -0.015834 16.43 0.072263 0.042 -0.20897 -0.1716 17.254 0.014422 0.06 -0.29284 -0.28771 28.034 -0.032916 0.039 -0.10147 -0.25037 19.002 0.0049062 0.047 -0.20429 -0.32994 18.277 -0.054305 0.037 -0.2644 -0.37067 16.178 -0.078131 0.046 -0.31964 -0.40951 21.855 -0.11888
OTOH, if you have a (again text) .mat file that is the temp array, then you could read it into the table directly as
fn='OctaveArrayDataFile.mat'; % assume text file
tData=readtable(fn,'FileType','text','VariableNames',vnames);
where like with load have to tell MATLAB a .mat file is in text format rather than native form.
You can then apply all the power of MATLAB to the table referencing each by name with whatever it is that is wanted to be done.
The Q? is how are you getting these .mat files -- are you creating them yourself or is somebody providing them? Can you (or they) change how they're being written to save as -V7 MATLAB .mat files in which case you'll get the variable names and sizes automagically.
What specifically is to be done might aid in other more specific recommenations.

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 約19時間 前
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 件のコメント
dpb
dpb 約19時間 前
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 約18時間 前
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by