Can somebody help me with this script?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am a new user of Matlab and I am not undertanding this section
clear;
warning off;
allData = [];
myfiles = uigetfile('*.mat','multiselect','on');
if ~iscell(myfiles)
load(myfiles);
allData = data;
else
for n=1:length(myfiles)
load(myfiles{n});
allData = [allData data];
end
end
2 commentaires
Adam
le 14 Fév 2018
Which bit in particular? If you are a new user then the Help is your best friend
doc clear
doc warning
doc uigetfile
doc iscell
doc load
doc for
doc if
etc. They will all explain the various commands in that script, so which bit is troubling you specifically, having looked at the help?
Réponses (1)
Adam
le 14 Fév 2018
Modifié(e) : Adam
le 14 Fév 2018
iscell
checks if you have a cell array. uigetfile will return a cell array if multiple files are selected, otherwise it will just return a char array.
So ~iscell covers the case of a char array, simply loading it as it is only one file.
The else deals with the case where you have multiple files in a cell array and thus creates a loop which takes each file from the cell array in turn and loads it.
load(myFiles{n})
does this by taking the nth element of the cell array of filenames and loading that since myFiles{n} evaluates to a single filename.
allData = [allData data];
concatenates the most recently loaded file (I assume, it isn't clear what is actually in these files, but from the code I assume each contains just a 'data' variable) input with the previous ones. What kind of format that takes I don't know as the concatenation operator will behave differently if data is a cell array of if it is a numeric array, etc.
0 commentaires
Voir également
Catégories
En savoir plus sur Cell Arrays 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!