You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to show the contents of a folder in app designer and plot the files in it ?
4 views (last 30 days)
Show older comments
Hi All
my code generates some excel files as output in a certain folder. which are a 2 column data. I was wondering if there is any way to show the content of this folder in a box as a list that dynamically updates as the code proceeds, or even just using a button that can update this box. then by hovering over each file name and selecting it from the box, I could plot it in a UIfigure plot in the app window. is this possible ?
Accepted Answer
Ameer Hamza
on 26 Mar 2020
See the attached app. It will list all the .xlsx file in the current folder and if it only has two columns, then plot it on the axes.
17 Comments
Ameer Hamza
on 26 Mar 2020
App designer was introduced in R2016a. Hopefully, it can be opened in R2017b.
farzad
on 26 Mar 2020
It didn't open with the 2017b, so maybe you saved it with a newer version despite it was done in 2016 versin. maybe you could just copy the whole in an m file or txt ?
Ameer Hamza
on 26 Mar 2020
I used the app designer to save a version compatible with R2017b. I think the file attached to this comment should work.
Ameer Hamza
on 26 Mar 2020
Also I forgot to change a line in this code which is compatible with R2017b. Please replace the readmatrix line in the code view with the following line
data = xlsread(filename);
farzad
on 26 Mar 2020
thank you so much !! it works perfectly ! just that I was trying to include the hold on button in my case, so that when I move from one file to the other one, if I have checked the hold on check button, it holds the previous figure
I did the follwing but it did not work
% Value changed function: HoldPlotsCheckBox
function HoldPlotsCheckBoxValueChanged(app, event)
value = app.HoldPlotsCheckBox.Value;
end
% Value changed function: FilesListBox
function FilesListBoxValueChanged(app, event)
switch app.HoldPlotsCheckBox.Value
case 0
app.selectplot= uigetfile();
drawnow;
% FocusUIFigure(app.UIFigure)
app.UIFigure.Visible = 'off';
app.UIFigure.Visible = 'on';
filename = app.FilesListBox.Value;
data = xlsread(filename);
plot(app.UIAxes, data(:,1), data(:,2));
case 1
app.selectplot= uigetfile();
drawnow;
% FocusUIFigure(app.UIFigure)
app.UIFigure.Visible = 'off';
app.UIFigure.Visible = 'on';
filename = app.FilesListBox.Value;
data = xlsread(filename);
plot(app.UIAxes, data(:,1), data(:,2));
hold on
end
end
farzad
on 26 Mar 2020
thank you , but I tried it and when I press down the Hold button, only the first graph is plotted and then if I click on the next files, nothing happnes untill I unpress the Hold
farzad
on 26 Mar 2020
and by the way I edited my code, it can only hold 2 plots, but also in a strange manner :
% Value changed function: HoldPlotsCheckBox
function HoldPlotsCheckBoxValueChanged(app, event)
value = app.HoldPlotsCheckBox.Value;
end
% Value changed function: FilesListBox
function FilesListBoxValueChanged(app, event)
switch app.HoldPlotsCheckBox.Value
case 0
cla(app.UIAxes)
drawnow;
% FocusUIFigure(app.UIFigure)
% app.UIFigure.Visible = 'off';
% app.UIFigure.Visible = 'on';
filename = app.FilesListBox.Value;
data = xlsread(filename);
plot(app.UIAxes, data(:,1), data(:,2));
case 1
drawnow;
% FocusUIFigure(app.UIFigure)
% app.UIFigure.Visible = 'off';
% app.UIFigure.Visible = 'on';
filename = app.FilesListBox.Value;
data = xlsread(filename);
plot(app.UIAxes, data(:,1), data(:,2));
hold(app.UIAxes);
end
farzad
on 26 Mar 2020
and one really more important question : How do I add a legend while I am holding the plots ??
Ameer Hamza
on 27 Mar 2020
"when I press down the Hold button, only the first graph is plotted and then if I click on the next files, nothing happnes untill I unpress the Hold"
Isn't it the required behaviour as you previously mentioned "I was trying to include the hold on button in my case, so that when I move from one file to the other one, if I have checked the hold on check button, it holds the previous figure"
Also coping the code is not helpful to check the issue with app designer. You can attached the .mlapp file so that i can directly open it in my PC.
For adding legend, please check the attached file.
farzad
on 27 Mar 2020
about plotting : the required was: when I press the hold, the app overlays the next plots on the first one, so I can compare them.
about the legend, I tried it. it does not work in the way I mentioned: it only writes one single legend line and inside is written mylegend. It does not grab the filenames I am clicking on.
what I needed is : when I click multiple files, and hold all the plots, the legend show a list of all those clicked and plotted files.
Ameer Hamza
on 27 Mar 2020
Ok. Suppose you press hold button, then click two filenames, does it need to show both plots? Then you click the hold button again, what should happen if you click other filenames after that? Should I remove two previous plots or it should still keep them?
farzad
on 27 Mar 2020
dear Ameer, as long as the hold button is pressed, it should keep any plot of the next clicked files with all the relevant legend in the legend list. Actually I somehow managed to solve it, but changing your code a little bit. just in case you don't want to dedicate time to that.
THANK YOU SO MUCH
farzad
on 6 Apr 2020
dear Ameer, I think you can help me with this new question of mine, it's relevant to this one :
More Answers (0)
See Also
Categories
Find more on Line Plots 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)