User input folder path in App Designer with multiple tables
显示 更早的评论
First time using this feature. I'm trying to have the user input their folder path and will display the calculation based on it.
I have the calculation code on a seperate file that is called when the calculate button is pressed.
function calculation(folderpath)
But other than that I'm not sure how to have
- what the user input = folderpath so the function can be run
- how to display the data in the correct table location

2 个评论
Geoff Hayes
2022-6-23
回答(1 个)
Jon
2022-6-23
You need to define a value changed callback function for each Edit Field, something like this for the first one, and then similar for the second one, except change the names appropriately, e.g. app.EditField -> app.EditField2
, app.UITable.Data ->app.UITable2.Data
% Callbacks that handle component events
methods (Access = private)
% Value changed function: EditField
function EditFieldValueChanged(app, event)
% get the folder path that the user entered
folderpath = app.EditField.Value;
% calculate the data using the data in this folder
data = calculation(folderpath)
% display the data in the appropriate table
app.UITable.Data = data
end
3 个评论
Jon
2022-6-23
Although the above approach is straightforward it requires essentially duplicating the same code twice, which isn't really very good practice. If you want to get more sophisticated you could use a single, common callback for when either edit box was changed and then assign the data to the appropriate table. To do this assign Tag names to each edit field. You can look at the event data passed to the EditFieldValueChanged function, specifically data.Source.Tag to see which one was called and branch accordingly to populate the correct table.
Emily
2022-6-23
The error message is telling you that your function, calculation, is not returning any output arguments, but you try to assign a value to the output, in your line
data=calculation(folderpath);
Please check that in your code for calculation that the first line assigns an output argument to the result of the calculation, that is the for example:
function outData = calculation(folderpath)
inData = readmatrix(fullfile(folderpath,'myData.csv'))
outData = inData*2; % just for example
end
If that doesn't fix your problem, please attach your code along with any necessary files to run it and I will see what is going on.
类别
在 帮助中心 和 File Exchange 中查找有关 Tables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!