Dynamic Drop Down Menu

21 views (last 30 days)
JoKi
JoKi on 1 Feb 2021
Commented: JoKi on 1 Feb 2021
Hi guys,
i have some data which i have read in to a table (using App Designer). It is possible to read in multiple files. The Data contains some general information in the header and then some force measurement signal. The signal is filtered and the maximum is shown in the table. So now i want to add a drop down menu to plot the graphs from the data. My Problem is that the number of graphs i want to plot depends on the number of files i've read in, so the number is changing. Im not sure how to solve this, so thanks for any help!
The Code i have to store the data in a table is:
function EinlesenButtonPushed(app, event)
%Diese Funktion dient dem direkten Lesen der auf dem übergeben Pfad
%hinterlegten CSV-Datei. Diese Datei muss exakt der Formatierung der
%Dateien entsprechen die das Program "Power" des Diagnostikgerätes
%liefert.
%Einlesen der Datei über den Umweg mit strings
% Öffnen eines Fensters zur Auswahl der zu öffnenden .csv Dateien.
[filename,pathname] = uigetfile('*.csv;','MultiSelect',"on");
for i = 1:length(filename)
filepath=fullfile(pathname, filename);
fid = fopen (filepath{i});
%[file,path]=uigetfile('*.csv');
A = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s%s%s','Delimiter',';');
%Umwandeln von Cell --> String
B=string([A{:}]);
%',' durch '.' ersetzen
B=replace(B,',', '.'); % ',' durch '.' ersetzen
% Aufteilen in Header und Messdaten
Daten(i).Header=B(1:30,:);
Daten(i).Messdaten=str2double(B(31:end,7));
end
for i = 1:length(filename)
%Uhrzeit / time
u= char(Daten(i).Header(12,1));
u1 = extractBetween(u,13,20 );
%Datum / date
d = char(Daten(i).Header(11,1));
d1 = extractBetween(d,11,20);
%Bein Seite / leg
be = char(Daten(i).Header(21,1));
if strlength(be) == 22
be1 = extractBetween(be,10,14);
else
be1 = extractBetween(be,10,15);
end
% Bewegung /
b = char(Daten(i).Header(23,1));
if strlength(b) == 32
b1 = extractBetween(b,13,21);
else
b1 = extractBetween(b,13,19);
end
% Kraft Tiefpass Filter / lowpass filter
x = Daten(i).Messdaten;
windowsize = 5;
c = (1/windowsize)*ones(1,windowsize);
a = 1;
y = filter(c,a,x);
M =max(y);
drop(i) = append(u1,' ',b1,' ',be1);
% Einlesen der Daten in Tabelle
data(i,:) = [d1 u1 b1 be1 M drop(i)];
end
app.UITable.Data = data;
end

Accepted Answer

Mario Malic
Mario Malic on 1 Feb 2021
Edited: Mario Malic on 1 Feb 2021
Hello,
Variable filename contains list of all files you're analysing?
You need to generate the cell of character arrays for Items property like this
ddItems = cell(length(filename), 1)
for ii = 1 : 1 : length(ddItems)
ddItems{ii} = sprintf('Data%d', ii);
end
app.DropDownMenu.Items = ddItems;
app.DropDownMenu.ItemsData = 1 : length(ddItems);
  5 Comments
Mario Malic
Mario Malic on 1 Feb 2021
Since, all of this is in for loop, you can set your y variable as a property of the app, so you can access it from anywhere within the app
x = Daten(i).Messdaten;
windowsize = 5;
c = (1/windowsize)*ones(1,windowsize);
a = 1;
app.y(i,:) = filter(c,a,x);
I do not know how does your app looks like, or how do you want to do the plotting, but you'll need to create a callback for the DropDownMenu component
function DropDownValueChanged(Source,Event)
index = app.DropDownMenu.Value;
plot(app.UIAxes, x,app.y(index,:)); % I am not sure what x is, if it's the first line from section above, then
% do the same as in y, make it x(i,:) and property of the app
end
Also, consider what happens when you change the dropdown value, do you want to add the data, or you want to plot only the selected one, you can use hold function to do it programmatically or change the settings in the UIAxes component.
hold(app.UIAxes, 'on') % example
JoKi
JoKi on 1 Feb 2021
That helps, again thanks alot!

Sign in to comment.

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!