How to properly extract dataset and load in new file? Keep getting error.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Stephen23
am 8 Jan. 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.
Akzeptierte Antwort
Stephen23
am 8 Jan. 2021
Bearbeitet: Stephen23
am 8 Jan. 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).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!