Plotting in app designer

조회 수: 3 (최근 30일)
Ville Saunajoki
Ville Saunajoki 2018년 2월 7일
댓글: Ville Saunajoki 2018년 2월 9일
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
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
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
Kai Domhardt
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
Ville Saunajoki 2018년 2월 9일
When the app designer adds a plot without data it lists the following
% Create UIAxes
app.UIAxes = uiaxes(app.Panel);
app.UIAxes.DataAspectRatio = [1 1 1];
app.UIAxes.PlotBoxAspectRatio = [1 1 1];
app.UIAxes.XLim = [0 1];
app.UIAxes.YLim = [0 1];
app.UIAxes.ZLim = [0 1];
app.UIAxes.CLim = [0 1];
app.UIAxes.GridColor = [0.15 0.15 0.15];
app.UIAxes.MinorGridColor = [0.1 0.1 0.1];
app.UIAxes.XColor = [0.15 0.15 0.15];
app.UIAxes.XTick = [0 0.2 0.4 0.6 0.8 1];
app.UIAxes.YColor = [0.15 0.15 0.15];
app.UIAxes.YTick = [0 0.5 1];
app.UIAxes.ZColor = [0.15 0.15 0.15];
app.UIAxes.ZTick = [0 0.5 1];
app.UIAxes.CameraPosition = [0.5 0.5 9.16025403784439];
app.UIAxes.CameraTarget = [0.5 0.5 0.5];
app.UIAxes.CameraUpVector = [0 1 0];
app.UIAxes.Position = [0 235 268 140];
In debugging most of those mode properties (XLimMode, PlotBoxAspectRatioMode, ZTickMode...) seem to be 'manual'. I guess that this specific declaration of properties sets their modes to 'manual'.
So I'll do a initialization function to set those modes of all graphs to 'auto' and then run it in start-up function. Hopefully that will auto scale all the later data.
As interesting work-around I tested to plot some random data points in start-up.
function startupFcn(app, args)
scatter(app.UIAxes, [1,2], [1,2]);
end
That did not scale automatically. So I need to separately declare those modes to 'auto'.
I hope this is a lesson for others or fix for the next update :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by