Can somebody help me with this script?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Adam
el 14 de Feb. de 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?
Respuestas (1)
Adam
el 14 de Feb. de 2018
Editada: Adam
el 14 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!