How to show the contents of a folder in app designer and plot the files in it ?
5 次查看(过去 30 天)
显示 更早的评论
farzad
2020-3-26
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 ?
采纳的回答
Ameer Hamza
2020-3-26
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 个评论
farzad
2020-3-26
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
2020-3-26
I used the app designer to save a version compatible with R2017b. I think the file attached to this comment should work.
Ameer Hamza
2020-3-26
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
2020-3-26
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
2020-3-26
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
2020-3-26
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
2020-3-26
and one really more important question : How do I add a legend while I am holding the plots ??
Ameer Hamza
2020-3-27
"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
2020-3-27
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
2020-3-27
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
2020-3-27
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
2020-4-6
dear Ameer, I think you can help me with this new question of mine, it's relevant to this one :
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)