uigetfile canceled returns 0, converting my string to a scalar
when I call [infile, location] = uigetfile() and it’s canceled, it returns 0s, converting my strings to a scalars
Next time I call it I get an error:
Error using uigetputfile_helper/checkString
Filename must be a character vector or a string scalar.
How do I get my string back for infile to be properly used next time?
This shouldn’t be that hard! I even tried converting the vars back to strings but it still fails after a cancel loop
function LoadfromTextFileButtonPushed(app, event)
% Open the file in the Load trials text
if isempty(app.loc)
[infile, app.loc] = uigetfile(‘*.txt’,’Select a Stimulus File’,app.defLoc);
else
[infile, app.loc] = uigetfile(‘*.txt’,’Select a Stimulus File’,app.loc);
end
if infile == 0 % user canceled
app.FileName.Text = ‘Click Load From Text File or enter manually’;
% give me back a string var for next time
infile = ”;
app.loc = app.defLoc; % return to default string
return;
end
% Put full file name into the File field name and read it in
locfile = fullfile(app.loc,infile);
app.FileName.Text = locfile;
app.UITable2.Data = readtable(locfile);
endwhen I call [infile, location] = uigetfile() and it’s canceled, it returns 0s, converting my strings to a scalars
Next time I call it I get an error:
Error using uigetputfile_helper/checkString
Filename must be a character vector or a string scalar.
How do I get my string back for infile to be properly used next time?
This shouldn’t be that hard! I even tried converting the vars back to strings but it still fails after a cancel loop
function LoadfromTextFileButtonPushed(app, event)
% Open the file in the Load trials text
if isempty(app.loc)
[infile, app.loc] = uigetfile(‘*.txt’,’Select a Stimulus File’,app.defLoc);
else
[infile, app.loc] = uigetfile(‘*.txt’,’Select a Stimulus File’,app.loc);
end
if infile == 0 % user canceled
app.FileName.Text = ‘Click Load From Text File or enter manually’;
% give me back a string var for next time
infile = ”;
app.loc = app.defLoc; % return to default string
return;
end
% Put full file name into the File field name and read it in
locfile = fullfile(app.loc,infile);
app.FileName.Text = locfile;
app.UITable2.Data = readtable(locfile);
end when I call [infile, location] = uigetfile() and it’s canceled, it returns 0s, converting my strings to a scalars
Next time I call it I get an error:
Error using uigetputfile_helper/checkString
Filename must be a character vector or a string scalar.
How do I get my string back for infile to be properly used next time?
This shouldn’t be that hard! I even tried converting the vars back to strings but it still fails after a cancel loop
function LoadfromTextFileButtonPushed(app, event)
% Open the file in the Load trials text
if isempty(app.loc)
[infile, app.loc] = uigetfile(‘*.txt’,’Select a Stimulus File’,app.defLoc);
else
[infile, app.loc] = uigetfile(‘*.txt’,’Select a Stimulus File’,app.loc);
end
if infile == 0 % user canceled
app.FileName.Text = ‘Click Load From Text File or enter manually’;
% give me back a string var for next time
infile = ”;
app.loc = app.defLoc; % return to default string
return;
end
% Put full file name into the File field name and read it in
locfile = fullfile(app.loc,infile);
app.FileName.Text = locfile;
app.UITable2.Data = readtable(locfile);
end uigetfile, cancel MATLAB Answers — New Questions