Plotting in app designer
显示 更早的评论
I am creating an app to quickly plot csv data. UiAxis for plot needs to be updated once the data is imported but I cannot get it working. The UIAxis element is done in app designer. Plotting is done with app's internal function:
methods (Access = private)
function results = plotWidths(app)
histogram(app.UIAxes, app.Data.Width)
end
The plot component (named UIAxes) is within a panel if that makes any difference. The property Data is a table that has a column Width.
Thank you already in advanced.
1 个评论
Birdman
2018-2-7
So basically, you want to upload some numerical data from your excel file and plot it on App Designer?
回答(1 个)
Kai Domhardt
2018-2-7
编辑:Kai Domhardt
2018-2-7
From what I can tell, your version should be working. I tested the following:
The structure of the components:
app.UIFigure
app.Panel
app.UIAxes
test.csv:
Width, Height
1, 7
2, 6
3, 5
4, 4
5, 3
6, 2
7, 1
The function from where the .csv is read and the plotWidths function is called. I chose the startupFcn for ease of testing, but it could be any other method or callback.
function startupFcn(app)
filename = 'test.csv';
csv_table = readtable(filename);
app.Data = csv_table;
plotWidths(app);
end
The same plotWidths method that you used:
function results = plotWidths(app)
histogram(app.UIAxes, app.Data.Width)
end
When I run this with Matlab R2017b it works without any errors. Does your use deviate in any meaningful way from this?
7 个评论
Ville Saunajoki
2018-2-7
编辑:Ville Saunajoki
2018-2-7
Kai Domhardt
2018-2-7
Can you provide us with the function that calls plotWidths?
Is it possible that you have multiple UIAxes in your UIFigure (possibly ones that are not visible) and are using the wrong handle?
Ville Saunajoki
2018-2-7
Kai Domhardt
2018-2-7
That code should work, but maybe your .csv is not formated correctly and a series of NaN values are returned for Width.
Maybe you have previous instance of the figure open, which would naturally not react to changes?
As a side note: you might want to rename your variable length, since length refers to the matlab function length
Ville Saunajoki
2018-2-7
Kai Domhardt
2018-2-7
The default value for UIAxes.XLimMode and UIAxes.YLimMode is 'auto', 'manual' would need to be set before plotting.
Ville Saunajoki
2018-2-9
类别
在 帮助中心 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!