How do I use 2 separate app DropDown components to plot different values stored in a table?

6 views (last 30 days)
I have a .txt file of n rows and m columns that is always in the same format but the number of cols and rows can vary. I have written a script that can put the parameters of the file into a table, and then pick the table headers out and assign them to an X and a Y drop down components (depedning on what the headers are for each col) but I would like for the user to decide which parameters from the drop downs they want to plot.
My code is below, I have a seperate code that works in a similar format if it assumes the headers are the same each time and I hard code them in but as I said I want to be able to pull the headers/drop down options from the file. I am stuck on this part however ann didn't find the app drop down doccumentation overly helpful. I cannot post the txt file as it contains work related material and data.
app.data = readtable(uigetfile('*.txt'));
app.UITable.Data = app.data;
app.UITable.ColumnName = app.data.Properties.VariableNames;
app.X_VariablesDropDown.Items = (app.data.Properties.VariableNames);
app.X_VariablesDropDown.ItemsData = {app.data(:,1), app.data(:,2),app.data(:,3),app.data(:,4),app.data(:,5),app.data(:,6), ...
app.data(:,7),app.data(:,8),app.data(:,9),app.data(:,10),app.data(:,11),app.data(:,12),app.data(:,13),app.data(:,14)};
app.X_VariablesDropDown.Value = app.X_VariablesDropDown.ItemsData;
app.Y_VariablesDropDown.Items = (app.data.Properties.VariableNames);
app.Y_VariablesDropDown.ItemsData = {app.data(:,1), app.data(:,2),app.data(:,3),app.data(:,4),app.data(:,5),app.data(:,6), ...
app.data(:,7),app.data(:,8),app.data(:,9),app.data(:,10),app.data(:,11),app.data(:,12),app.data(:,13),app.data(:,14)};
app.Y_VariablesDropDown.Value = app.Y_VariablesDropDown.ItemsData;
strcmp(app.X_VariablesDropDown.ItemsData, app.Y_VariablesDropDown.ItemsData)
plot(app.UIAxes, app.data, app.data, 'k--.', LineWidth=1);
xlabel(app.UIAxes, app.X_VariablesDropDown.Items);
ylabel(app.UIAxes, app.Y_VariablesDropDown.Items);

Answers (1)

Sandeep Mishra
Sandeep Mishra on 4 Jul 2023
Hello Cathal,
I understood that you are trying to fetch some n*m table data and want to fill X and Y dropdown with table headers and plot the result based on X and Y dropdown values.
In MATLAB, uidropdown contains "ValueChangedFcn" callback which executes when the user selects a different option from the drop-down list.
You can create two callbacks for both dropdowns and plot the result based on selected options.
You can refer to the below documentation to learn more about "uidropdown" in MATLAB.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!