How to load data from Octave?

236 Ansichten (letzte 30 Tage)
Svit
Svit am 13 Feb. 2026 um 14:32
Bearbeitet: dpb vor etwa 11 Stunden
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"
^^^^

Akzeptierte Antwort

dpb
dpb am 13 Feb. 2026 um 16:06
Bearbeitet: dpb am 13 Feb. 2026 um 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).
  16 Kommentare
dpb
dpb vor etwa 16 Stunden
Bearbeitet: dpb vor etwa 11 Stunden
type Slovenia.m
temp=[0.067000000000000032 0.037379400869470003 0.18433509276973001 31.625314864252278 0.11012293770926 0.039000000000000055 -0.098394170124067995 -0.015833599156080999 16.429879165748627 0.072263225854672999 0.04200000000000003 -0.20897192803268 -0.17160003436134 17.253586158987421 0.014421521398178001 0.059999999999999998 -0.29283559910042001 -0.28770670889798 28.033902411104663 -0.032916262883566 0.038999999999999917 -0.10146584250649 -0.25036670679050999 19.001814229434107 0.0049062254220970996 0.046999999999999889 -0.20429439507207001 -0.32993983543960997 18.276585537724589 -0.054305047702654 0.036999999999999887 -0.26440474434417 -0.37066932633930999 16.178059503327205 -0.078131492314752998 0.045999999999999944 -0.31964282866976002 -0.40950773536436003 21.854836660928978 -0.11888495086585001 0.025000000000000001 -0.0022657586841141998 -0.12579270116769001 13.400393551190914 -0.14382118452993001 0.012000000000000028 -0.095910013338454003 -0.068395821076882996 4.9267771927383892 -0.15865466410793999 0.020999999999999942 -0.16742214225863999 -0.14130981443303001 5.7056161775867063 -0.18888841668010001 0.024999999999999859 -0.17761643106189001 -0.23741760397798001 10.829103467288945 -0.20153368607849001 0.032000000000000028 -0.22522551133553001 -0.35630283995394002 11.433980877431225 -0.22684656531196001 0.023000000000000003 -0.20402129374448999 -0.30616891494901999 13.200457955460386 -0.22413895062059 0.0010000000000000002 -0.19569258573024001 -0.27869030634421998 8.6720463102923535 -0.19869499685799 0.022000000000000002 -0.26225142120932998 -0.32993656079351003 5.7216922068153693 -0.22861064374699999 0.025000000000000001 -0.24891190198117999 -0.37749205748768 7.5727936225931103 -0.25565880821720999 0.028999999999999998 -0.19324850062603 -0.26940047412780999 8.3223589200638841 -0.24349508263361 0.012 -0.17950078489311 -0.27290394490782999 9.5253654746871117 -0.20272869929531001 0.019 -0.20778447010674 -0.27664085013593998 9.95074309945098 -0.19574114568376 0.029999999999999999 -0.18780579699354 -0.32151434120414002 10.205947749494156 -0.19421288978081999 0.017999999999999999 -0.18335740986480001 -0.20885464714794999 10.070329697222013 -0.14845159115310999 0.0030000000000000005 -0.17105040183035 -0.16920757669697001 7.802302879206624 -0.14362071963987 0.012000000000000002 -0.13680269573661999 -0.15418772538114001 6.1181169643276396 -0.14069776045318999 0.017000000000000001 -0.12140359754753 -0.18411379976461001 6.2733333333333334 -0.12298208253872001 0.0089999999999999993 -0.0049677344534507003 -0.090771002428379002 4.9233333333333329 -0.10612438962314 0.032000000000000001 -0.17797187464586001 -0.14827138549218 6.1366666666666667 -0.14164238392407999 0.019 -0.12117775980487 -0.094753022108476997 7.8033333333333337 -0.12186499819912 0.026000000000000002 -0.10883339019054999 -0.14214686580905 8.7866666666666671 -0.11759674896774 0.017000000000000001 -0.11590149404296 -0.076910656650236997 9.2066666666666688 -0.081466235936520998 0.025000000000000001 -0.086595884645343998 -0.082292930003423997 9.1066666666666674 -0.084342988500453006 0.018000000000000002 -0.079392024140489001 -0.057907180957338003 9.1066666666666674 -0.066246814419201994 0.027000000000000003 -0.088748692284989994 -0.10474785601495 8.8800000000000008 -0.058463783537209997 0.024 -0.080950220987433 0.0052932671921413002 9.2000000000000011 -0.0090143124243748998 0.011000000000000001 -0.045120125337948999 -0.011445580659398999 9.086666666666666 -0.012867644071298 0.0060000000000000001 -0.066668137147345 0.013156283753577001 7.3833333333333329 0.021074042169290999 0.032000000000000001 -0.092745547667948 -0.052253447800615999 7.8033333333333337 0.021112850961322999 0.017000000000000001 -0.076188528834755007 0.036005464762338998 8.4666666666666668 0.020152884524151 0.014999999999999999 -0.062472779216366001 0.018086196978288002 8.6333333333333329 0.012098414901814 0.0060000000000000001 -0.022747127280410999 0.025930583348817999 7.2000000000000002 0.040381268311121002 0.025000000000000001 -0.041201541729576997 -0.048969001717948997 7.580000000000001 -0.002216707385168 0.016 0.0010383769729954001 0.053982070487270002 6.8299999999999992 -0.012873891667434001 0.0039999999999999992 0.0063087906611922996 0.042007773440067002 6.4699999999999998 -0.013351975920894 0.0030000000000000005 0.012835983945688001 0.026407281392838999 6.2466666666666661 -0.028767179110874001 0.012999999999999998 0.028058788637644001 -0.056365882278379 5.8099999999999996 -0.058110282674146002 0.019 0.0069783779774139996 0.036856102386085998 4.7366666666666672 -0.070173237340126995 -0.002 0.045574213797647999 0.034261674533187 4.0366666666666662 -0.055139459809027 0.0019999999999999996 0.016226124733489 0.026050772876184 4.0700000000000003 -0.061575023424675003 0.013000000000000001 -0.014844206158443 -0.058811228119356997 4.0499999999999998 -0.066242550737069 0.0040000000000000001 0.019732429504136 0.065813246128702999 4.0499999999999998 -0.16760238204395 0.013000000000000001 -0.0026228414100515 0.025876174862435999 4.0300000000000002 -0.196109161285 -0.0050000000000000001 0.033346683900483003 0.011033468265979 4.0066666666666668 -0.14604138565107 0.0069999999999999993 0.00072768230242382004 -0.069913439239032996 3.7899999999999996 -0.11469636080789 0.014999999999999999 -0.0048093878415756 0.034943839774338001 3.4599999999999995 -0.095172710163122995 0.0069999999999999993 0.035467986382197003 0.019007711482967 3.4700000000000002 -0.064253413188418998 5.5511151231257828e-19 0.072506464829289005 0.0048145757131799003 3.6033333333333331 -0.039786729668775001 0.005000000000000001 0.031654398221884997 -0.038982152300721003 3.82033333333333 -0.053721518260111997 0.025000000000000001 0.028274338491444999 0.060887751226179003 4.0648333333333335 -0.043190229286851997 0.0040000000000000001 0.052246065299054997 0.065464552683143995 4.5004999999999997 0.018266575657361998 0.02 0.0033900292692380998 0.017345758180361 4.7247666666666666 -0.0070845290557794999 0.013000000000000001 0.051303369831173 -0.020589792895865999 4.4800000000000004 0.00069909376095367 0.027999999999999997 0.035258859538723999 0.064194004510487998 4.8604666666666665 -0.013579471739238 -0.0069999999999999993 0.033966170306456003 0.062378014928924003 4.9818000000000007 0.029727126839218 -0.016 -0.085748597659701997 0.0092009401987986992 4.214666666666667 0.058227753069685001 0.011000000000000001 -0.21234533809303999 -0.088292429009035001 2.0116999999999998 0.045925555341059 0.013000000000000001 -0.21550343295612001 -0.0099519738128020004 1.3106333333333333 0.045396880080193998 -0.0080000000000000002 -0.18447501114709 0.022058562330121999 0.86920000000000008 0.038767997070615998 0.0050000000000000001 -0.21009337053298999 -0.013522578879816 0.7219000000000001 0.014929464115394 0.0069999999999999993 -0.24333673888578 -0.10529325954528999 0.66213333333333335 0.0038098898122810999 0.017000000000000001 -0.181664917137 -0.01522932467374 0.68626666666666658 -0.0059461969700933997 -0.0090000000000000011 -0.14559929720133999 0.017794714641837999 0.87493333333333323 0.012099147327446999 0.0050000000000000001 -0.10581975146496 -0.011554859153243001 1.0204666666666666 -0.0067927876356713001 0.0099999999999999985 -0.088672669175020993 -0.10626781366497 1.0931333333333333 -0.016164712782643 0.0080000000000000002 -0.078504419821289001 -0.0083473426333702007 1.4116333333333333 -0.013793831399934 -0.0020000000000000005 -0.048513482864520001 0.022921742379013 1.5620666666666665 0.0021082647479104999 0.0050000000000000001 -0.019207632780079999 -0.0081487141500193993 1.4955666666666667 -0.0028495089865181 0.013000000000000001 -0.041710931458545999 -0.090736567131881996 1.0429999999999999 -0.0073873281217836 0.0090000000000000011 -0.029483241165686999 -0.029779190707726 0.69603333333333328 -0.0069668283719934998 0.01 0.00041846761090447003 -0.0066951777386722996 0.35856666666666664 -0.017320766085350998 -0.0010000000000000002 -0.0071406402814249001 -0.0086027498926695006 0.19513333333333335 -0.021942120839813999 0.0049999999999999992 0.068113246684096004 -0.11629607534965 0.21146666666666666 -0.024511902136402999 0.0089999999999999993 0.051547955485397999 -0.030675323276014001 0.20679999999999998 -0.033837404697922999 0.0040000000000000001 0.054518552294269003 0.0065763064421977997 0.2235 -0.027381682343935999 -0.0069999999999999993 0.094878347986101993 0.020785075755057999 0.2409 -0.028277811843547999 0.0009999999999999998 0.078259766305579001 -0.074598895195357007 0.2951333333333333 -0.02170168981386 0.013000000000000001 0.060586902349478 -0.0084770380065917004 0.2985666666666667 -0.017606892411101999 -0.0080000000000000002 0.078864146007737002 0.028473041251463001 0.16456666666666667 0.017756025574367999 -0.0069999999999999993 0.032697589718012003 0.020827458938114999 0.081466666666666673 0.0097786761957863004 -0.0009999999999999998 0.056247216389234002 -0.061268891366963001 0.046033333333333336 0.0068990408934545997 0.0069999999999999993 0.045727088198640999 0.011783825468731 -0.0065333333333333328 0.0038665447159047998 -0.0080000000000000002 0.049553742796544002 0.040253704861668002 -0.027800000000000002 0.021178147529934001 -0.002 0.045352397958228999 0.025891037238841001 -0.089166666666666658 0.013837648958383001 -0.0059999999999999984 -0.017092886037471 -0.047987891668625 -0.18606666666666669 0.029214550894596999 0.016 -0.0075663467091890996 0.015616055437724 -0.2581 0.013095551579717001 -0.0069999999999999993 0.030701039487054001 0.066595219637543002 -0.29809999999999998 0.038518044513572998 0.0009999999999999998 0.040317052471765001 0.053797554307763 -0.3125 0.034919109316394997 0.0089999999999999993 0.061196840998367003 -0.052808034286070997 -0.32779999999999998 0.033402357870845001 0.0060000000000000001 0.067855974614152006 0.022828347872613002 -0.32996666666666669 0.029137530876316001 -0.002 0.062338435558049 0.056611468893191998 -0.32963333333333339 0.034372739559412002 0.0069999999999999993 0.092882060707471001 0.057731682904596002 -0.32880000000000004 0.026194398669709001 0.0040000000000000001 0.076429080290760995 -0.045962246694870999 -0.32830000000000004 0.028312459904814 0.013999999999999999 0.069579469925841006 0.022135532109809002 -0.32523333333333332 0.020238508699176001 -0.0030000000000000005 0.093328734844229003 0.065924937073952999 -0.31949999999999995 0.033725911818923003 -0.0009999999999999998 0.085839940209259002 0.074628606728460001 -0.31533333333333335 0.026419729129852 0.0049999999999999992 0.069372583082371 -0.061236873363729002 -0.30853333333333333 0.022837211903472002 0.018000000000000002 0.041208160425672997 0.019815149021349 -0.31709999999999999 0.01365543700172 -0.0039999999999999992 0.021557016421538001 0.076524591751176999 -0.39673333333333333 0.031825490194894002 0 -0.022200471431363 0.049669756215859 -0.4029666666666667 0.014494388299074 -0.0069999999999999993 -0.043437691342452997 -0.13002122863481 -0.40549999999999997 0.0035094944534535002]; Dataslpiobs=temp(:,1); Dataslinobs=temp(:,2); Dataslcobs=temp(:,3); Dataslrobs=temp(:,4); Dataslmobs=temp(:,5);
Well, certainly pasting in data manually into an m-file isn't "the MATLAB way". I don't see what is the issue that has you stymied, but starting with the Octave-generated (I presume?) file, the prior code works just fine...
fn='Slovenia_centered.mat'; % set the file name -- change as needed for other files
load('-ascii',fn) % assume was written with -ascii switch in Octave so is vector
% the loaded variable will be the same as the name of the .mat file, "Slovenia_centered"
%whos
try % make sure can split into five variables
assert(mod(numel(Slovenia_centered),5)==0)
catch
error('Vector length (%d) not compatible; unable reshape to 5 variables. Aborting.', ...
numel(Slovenia_centered))
end
Slovenia_centered=reshape(Slovenia_centered,[],5); % reshape to 2D presuming are 5 variables
vnames={'Dataslcobs','Dataslinobs','Dataslmobs','Dataslpiobs','Dataslrobs'};
for i=1:numel(vnames)
cmd=sprintf('%s=Slovenia_centered(:,i);',vnames{i}); % make a command to execute
eval(cmd); % and evaluate the string
end
clear Slovenia_centered % remove the vector copy -- no need to keep two copies of same data
At this point you will have the five D* variables by the names given in the vnames list -- change it to correct any typos or make other desired/needed changes, if any were ever required. The code does presume and require that the size of the imported data vector be evenly divisible by 5; if that were to ever change, the appropriate changes would be required in the testing code and the names array to match.
Above you wrote "I assume the obtained data in 5 columns is now saved in file Slovenia_centered.mat, right?"
The answer to that is a resounding "NO!". Rearranging the data in memory has nothing to do with changing the format or arrangement of the data in the disk file.
As noted in the prior comment, IF you were to save the data now into a .mat file, you could write it that way, yes. But, having done so, then you don't need (and can't use) this code to read the -ascii version. That would not be a bad thing if this has need of being done more than once, but you would then have to be sure to use the right code for the job. There isn't a specific builtin function in MATLAB to query the internal form of a .mat file, but one can query the content of variable(s) in the file using the whos command with the -file argument to find out if the D* variables are there or not and choose which code to run based on that...
% save the specific D* variables in native MATLAB .mat file
save Slovenia_centered.mat Dataslcobs Dataslinobs Dataslmobs Dataslrobs Dataslpiobs
The above replaces the original .mat file in ASCII vector format with the native binary format and keeps the five variables separate.
dir *.mat % see what is there -- is same file name as before
Slovenia_centered.mat
v=whos('-file',fn,'D*') % query the file content of variabless beginning with "D"
v = 5×1 struct array with fields:
name size bytes class global sparse complex nesting persistent
and we see there really are five of them as expected.
So, we could write code something like(*)
if numel(whos('-file',fn,'D*'))==5 % see if we have five D* variables in the file
load fn % if so, load them directly
else
% the above code to read the Octave -ascii version and create the D*
% variables would go in here...as well as the |save| command so that only
% do it when starting with the -ascii version.
end
(*) The above checks if the file contains fiive (5) variables whos names start with "D". An alternative way would be to just try to read the file as -ascii as was originally and trap the error and then presume is the desired format...
try % presume is the -ascii version first
% the above code to read the Octave -ascii version and create the D*
% variables would go in here...as well as the save command so that only
% do it when starting with the -ascii version.
catch
load(fn) % if not, assume can load them directly
end
it's in the eye of the beholder which to use...
dpb
dpb vor etwa 14 Stunden
Bearbeitet: dpb vor etwa 11 Stunden
ADDENDUM SECOND:
Of course, the neat way to code this would be to encapsulate the work to read the -ascii version in a function -- that hides the dirty details from the top level code...
function [Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs] = readASCIImat(fn)
% read Octave-generated ASCII .mat file as vector and return five specific variables
% USAGE
% [Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs] = readASCIImat(file)
load('-ascii',fn) % assume was written with -ascii switch in Octave so is vector
try % make sure can split into five variables
assert(mod(numel(Slovenia_centered),5)==0)
catch
error('Vector length (%d) not compatible; unable reshape to 5 variables. Aborting.', ...
numel(Slovenia_centered))
end
Slovenia_centered=reshape(Slovenia_centered,[],5); % reshape to 2D presuming are 5 variables
vnames={'Dataslcobs','Dataslinobs','Dataslmobs','Dataslpiobs','Dataslrobs'};
for i=1:numel(vnames)
cmd=sprintf('%s=Slovenia_centered(:,i);',vnames{i}); % make a command to execute
eval(cmd); % and evaluate the string
end
% save the specific D* variables in native MATLAB .mat file
save Slovenia_centered.mat Dataslcobs Dataslinobs Dataslmobs Dataslrobs Dataslpiobs
end
Then the above logic in your main program would look like
fn='Slovenia_centered.mat'; % set the file name -- change as needed for other files
try % presume is the -ascii version first
[Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs] = readASCIImat(fn);
disp(['Reading -ASCII .mat file ' fn])
catch
disp(['Loading native .mat file ' fn])
load(fn) % if not, assume can load them directly
end
Reading -ASCII .mat file Slovenia_centered.mat
% Have the specific five D* variables in memory now
% Just to show it does what want, we'll make into a table so can use head()
% conveniently to show resutls...this is only for show, not necessary
% unless you find a use for the table as well...
tS=table(Dataslcobs,Dataslinobs,Dataslmobs,Dataslpiobs,Dataslrobs);
head(tS,5)
Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs __________ ___________ __________ ___________ __________ 0.24359 0.089221 0.15389 26.45 0.054688 0.043417 -0.046553 0.11604 11.254 0.026688 -0.11235 -0.15713 0.058193 12.078 0.029688 -0.22846 -0.24099 0.010856 22.858 0.047688 -0.19112 -0.049624 0.048678 13.826 0.026688
% Whatever else you need to do comes next goes after...
Now, let's do this again and see what happens...
try % presume is the -ascii version first
[Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs] = readASCIImat(fn);
disp(['Reading -ASCII .mat file ' fn])
catch
disp(['Loading native .mat file ' fn])
load(fn) % if not, assume can load them directly
end
Loading native .mat file Slovenia_centered.mat
tS=table(Dataslcobs,Dataslinobs,Dataslmobs,Dataslpiobs,Dataslrobs);
head(tS,5)
Dataslcobs Dataslinobs Dataslmobs Dataslpiobs Dataslrobs __________ ___________ __________ ___________ __________ 0.24359 0.089221 0.15389 26.45 0.054688 0.043417 -0.046553 0.11604 11.254 0.026688 -0.11235 -0.15713 0.058193 12.078 0.029688 -0.22846 -0.24099 0.010856 22.858 0.047688 -0.19112 -0.049624 0.048678 13.826 0.026688
We see it read the -ascii file the first pass as started with a copy of the original posted file. The second time it read the rewritten native format file instead since the first past rewrote it. Note that the disp() call is after the attempt to read the file so the error occurred trying to read as ascii so the catch clause was entered before reaching the disp() call.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 13 Feb. 2026 um 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 Kommentare
dpb
dpb am 13 Feb. 2026 um 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 am 13 Feb. 2026 um 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by