Using drop-down list selection to plot
Show older comments
I am building an app that should do a few simple things:
- imports large csv files. The file is a table with datetime and approx. double variables. 25 in total.
- Plot chosen variables based on drop-down lists on a graph
- Export the graph to pdf
The problem I'm having is with the Drop-down list. I can populate the list with the variable names, however, I am struggling to link the selected variable to its column in the imported file and then plot the data. For reference, these variable can change with each import and therefore can't be fixed - I need them to be read in. I don't quite understand the syntax to relate the DropDown.Item.Value to the matrix contents.
I'm using version R2020b and I have tried for a while with other posts in the forum and documentation with little success.
I've posted some of the code below of where it works up to.
Can anyone help me out?
[file] = uigetfile('*.csv');
if isequal(file,0)
msgbox('Please input a CSV file')
else
app.SD = importdatav7(file);
isequal(file, 1)
opts = detectImportOptions(file, "NumHeaderLines", 24, "VariableNamesLine", 1);
% Create Variable1DropDownLabel
app.dd1Label = uilabel(app.LeftPanel);
app.dd1Label.HorizontalAlignment = 'right';
app.dd1Label.Position = [47 275 71 22];
app.dd1Label.Text = 'Variable 1';
% Create Variable1DropDown
app.dd1 = uidropdown(app.LeftPanel);
app.dd1.DropDownOpeningFcn = createCallbackFcn(app, @Variable1DropDownOpening, true);
app.dd1.Position = [136 275 100 22];
% Create Variable2DropDownLabel
app.dd2Label = uilabel(app.LeftPanel);
app.dd2Label.HorizontalAlignment = 'right';
app.dd2Label.Position = [60 235 58 22];
app.Vdd2Label.Text = 'Variable 2';
% Create Variable2DropDown
app.dd2 = uidropdown(app.LeftPanel);
app.dd2.Position = [137 235 99 22];
% Create Variable3DropDownLabel
app.dd3Label = uilabel(app.LeftPanel);
app.dd3Label.HorizontalAlignment = 'right';
app.dd3Label.Position = [63 192 58 22];
app.dd3Label.Text = 'Variable 3';
% Create Variable3DropDown
app.dd3 = uidropdown(app.LeftPanel);
app.dd3.Position = [136 192 100 22];
labels = opts.VariableNames;
app.dd1.Items = labels;
app.dd2.Items = labels;
app.dd3.Items = labels;
msgbox("Import Successful!")
end
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification 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!