How to save label in 1x1 categorical?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have .mat file which dimension is (1024x1) and i want to give name that .mat file in 1x1 categorical. when i load that .mat file the output shoud be
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/589742/image.png)
0 commentaires
Réponses (1)
Walter Roberson
le 20 Avr 2021
projectdir = '/path/to/files'; %could be '.'
dinfo = dir( fullfile(projectdir, '*.mat'));
filenames = fullfile({dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
frames = cell(nfiles,1);
labels = cell(nfiles,1);
%do not assume that the variable names are the same for each time
for K = 1 : nfiles
thisfile = filenames{K};
[~, basename, ~] = fileparts(thisfile);
filestruct = load(thisfile);
fields = fieldnames(filestruct);
frames{K} = filestruct.(fields{1});
labels{K} = categorical(basename);
end
output = cell2struct([frames,labels], {'frame', 'label'}, 2);
The output will be a (number of files x 1) struct array with fields 'frame' and 'label'
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!