Unassigned output arguments - How to handle the 'Cancel' button in the App Designer

8 views (last 30 days)
I have written a simple function to locate and tabulate data based on three user inputs. I use an input dialogue to gather the user input and generate a filepath. I have called this function with a button in an App constructed in the App designer. If the user fills in the three fields then the function operates as intended.
However, if the user presses 'cancel' then, naturally, the various function outputs are not assigned and the App Designer throws up an error, to the effect that:
Output argument "data1" (and maybe others) not assigned during call to "dataPull".
How can I suppress this error? The function's code is below; as you can see, I have run an if/return clause for an empty userInput, but this measure has not succeeded in suppressing the output error in the App Designer. I would appreciate any assistance in this matter.
% Generates a filepath from which to pull sensor data, based on three input
% strings, 'Zone', 'Month' and 'Year'; e.g. 'Foundry','Jan','2018'. A table
% is then produced from the data found in the specified directory.
%%Dialogue Box
prompt = {'Select Work-Centre','Enter the Month (e.g. "Jan")','Enter the Year'};
title = 'Select Data to Import';
dims = [1 50];
userInput = inputdlg(prompt,title,dims);
if isempty(userInput)
return
end
%%File Path
Zone = ['Temp & Humidity ' userInput{1}];
Month = [userInput{1} ' ' userInput{2}];
Year = userInput{3};
dataPath = fullfile('\\BRAFEWS\Shared\QIENG\Temp & Humidity Files',Zone,Year,Month);
data = readtable(dataPath);
%%Tabular Formatting
combiDate = datetime(data.DATE,'InputFormat','dd.MM.yy');
dateTime = combiDate + data.TIME;
data1 = data(:,{'TEMPERATURE','RELATIVE_HUMIDITY','DEW_POINT'});
data1.DATE = dateTime;
data1 = data1(:,{'DATE','TEMPERATURE','RELATIVE_HUMIDITY','DEW_POINT'})
end
Image of the error:

Accepted Answer

Jan
Jan on 16 Apr 2018

What about inserting a dummy value for data1:

if isempty(userInput)
  data1 = [];   % <== inserted
  return
end

Now catch this in the caller:

result = dataPull;
if isempty(result)
  return;
end
app.data = result:

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!