I have a question about the following code.
[name file] = uigetfile('*', 'Select an image');
if [name file] ~= 0
%file found
end
Is there a way of saying that [name file] can be assigned to an array? For example, Filepath[2] = ui.getfile.. (this doesn’t work).
When I tried the following code, I only get the filename and not the path. Am I declaring this array wrong?
Filepath{2} = uigetfile({'*.wav;*.mp3;*.aac;*.ogg'}, 'Select a file');
%Filepath{2} = uigetfile('*', 'Select an image');
%noFile = Filepath(0);
%if Filepath[1]~= 0
%if Filepath ~= 0
disp('Loading signal');
disp(Filepath);
%disp(Filepath{0});
disp('Filepath{1}');
disp(Filepath{1});
disp('Filepath{2}');
disp(Filepath{2});
I think you may be confused about the syntax for multiple “output arguments” of a function. Unlike most programming languages, MATLAB allows functions to have multiple return values; these are called output arguments. When you have a function
[a b] = foo(x), it is best to think of this as just the syntax to send the first output to a variable calledaand the second output to a variable calledb. Even though the syntax[a b]looks like an array, it is best to not think of it that way.Here’s an example of
uigetfile:which gives the filename and path of the selected file, in variables called
filenameandpathname, respectively.Why not try it out?
It appears that both outputs are 0 if the
uigetfileis cancelled. So you can do this: