How to properly extract dataset and load in new file? Keep getting error.

2 visualizzazioni (ultimi 30 giorni)
I have original dataset from which I have extract subset
% Load original data variable: 100 x 100 x 1000 x 500
folder = 'C:\Users\ABC\Desktop\Raw';
dname = "D";
X = load(strcat(folder,'\',dname,'_X.mat'));
X = X.data();
% Extract from variable 10 x 10 x 10 x 10 subset and save
Xs = X(1:10;1:10;1:10;1:10);
save ('D_Xs.mat', Xs)
Now when I open a new file and try to load in the extracted subset I get an error stating no data.
% Loading Ex
folder = 'C:\Users\ABC\Desktop\Raw';
dname = "D";
X = load(strcat(folder,'\',dname,'_Xs.mat'));
X = X.data();
  1 Commento
Stephen23
Stephen23 il 8 Gen 2021
You data importing uses absolute paths (which is good), but your data exporting does not (which is bad):
save(fullfile(folder,'D_Xs.mat'), Xs)
Using fullfile is recommended over string concatenation.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 8 Gen 2021
Modificato: Stephen23 il 8 Gen 2021
There is no data field because you saved the array using the name Xs. So you need to use the field Xs (and get rid of the superfluous parentheses):
tmp = load(strcat(folder,'\',dname,'_Xs.mat'));
X = tmp.Xs;
% ^^ use the correct field name
If you want the variable in the new mat file to be named data, then you need to name it data (and not Xs).

Più risposte (0)

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by