MATLAB Answers

0

how can i plot a graph in app designer?

Lala0099 님이 질문을 제출함. 9 Apr 2019
최근 활동 Hakob Bazoyan 님이 답변함. 18 Aug 2019
i have created 3 "axis" and a push button.
I have saved 3 variables in a mat file that I would like to display as a histogram. I loaded the file, but cannot display it on the graph. Any suggestion how to do it?
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
SwingarmButton matlab.ui.control.StateButton
LiftuparmButton matlab.ui.control.StateButton
RotateButton matlab.ui.control.StateButton
ReachandretrieveButton matlab.ui.control.StateButton
UnknownButton matlab.ui.control.StateButton
UIAxes matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
UIAxes3 matlab.ui.control.UIAxes
StartanalysisButton matlab.ui.control.Button
end
methods (Access = private)
% Button pushed function: StartanalysisButton
function StartanalysisButtonPushed(app, event)
% load ('dataTransformer.mat','N_XPA','N_YPA','N_ZPA')
load ('jerk_metric.mat', 'N_XPA','N_YPA','N_ZPA')
% plot(app.UIAxes,[0,1,2,3,], 'N_XPA')
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 827 589];
app.UIFigure.Name = 'UI Figure';
% Create SwingarmButton
app.SwingarmButton = uibutton(app.UIFigure, 'state');
app.SwingarmButton.Text = 'Swing arm';
app.SwingarmButton.Position = [694 559 119 22];
% Create LiftuparmButton
app.LiftuparmButton = uibutton(app.UIFigure, 'state');
app.LiftuparmButton.Text = 'Lift up arm';
app.LiftuparmButton.Position = [695 520 119 22];
% Create RotateButton
app.RotateButton = uibutton(app.UIFigure, 'state');
app.RotateButton.Text = 'Rotate';
app.RotateButton.Position = [695 485 119 22];
% Create ReachandretrieveButton
app.ReachandretrieveButton = uibutton(app.UIFigure, 'state');
app.ReachandretrieveButton.Text = 'Reach and retrieve';
app.ReachandretrieveButton.Position = [696 449 119 22];
% Create UnknownButton
app.UnknownButton = uibutton(app.UIFigure, 'state');
app.UnknownButton.Text = 'Unknown';
app.UnknownButton.Position = [697 409 119 22];
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Jerkiness')
xlabel(app.UIAxes, 'Movement')
ylabel(app.UIAxes, 'value_Y')
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 = [366 396 300 185];
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Peak numbers')
xlabel(app.UIAxes2, 'Movement')
ylabel(app.UIAxes2, 'Value')
app.UIAxes2.DataAspectRatio = [1 1 1];
app.UIAxes2.PlotBoxAspectRatio = [1 1 1];
app.UIAxes2.XLim = [0 1];
app.UIAxes2.YLim = [0 1];
app.UIAxes2.ZLim = [0 1];
app.UIAxes2.CLim = [0 1];
app.UIAxes2.GridColor = [0.15 0.15 0.15];
app.UIAxes2.MinorGridColor = [0.1 0.1 0.1];
app.UIAxes2.XColor = [0.15 0.15 0.15];
app.UIAxes2.XTick = [0 0.2 0.4 0.6 0.8 1];
app.UIAxes2.YColor = [0.15 0.15 0.15];
app.UIAxes2.YTick = [0 0.5 1];
app.UIAxes2.ZColor = [0.15 0.15 0.15];
app.UIAxes2.ZTick = [0 0.5 1];
app.UIAxes2.CameraPosition = [0.5 0.5 9.16025403784439];
app.UIAxes2.CameraTarget = [0.5 0.5 0.5];
app.UIAxes2.CameraUpVector = [0 1 0];
app.UIAxes2.Position = [366 203 300 185];
% Create UIAxes3
app.UIAxes3 = uiaxes(app.UIFigure);
title(app.UIAxes3, 'Entropy')
xlabel(app.UIAxes3, 'Movement')
ylabel(app.UIAxes3, 'Value')
app.UIAxes3.DataAspectRatio = [1 1 1];
app.UIAxes3.PlotBoxAspectRatio = [1 1 1];
app.UIAxes3.XLim = [0 1];
app.UIAxes3.YLim = [0 1];
app.UIAxes3.ZLim = [0 1];
app.UIAxes3.CLim = [0 1];
app.UIAxes3.GridColor = [0.15 0.15 0.15];
app.UIAxes3.MinorGridColor = [0.1 0.1 0.1];
app.UIAxes3.XColor = [0.15 0.15 0.15];
app.UIAxes3.XTick = [0 0.2 0.4 0.6 0.8 1];
app.UIAxes3.YColor = [0.15 0.15 0.15];
app.UIAxes3.YTick = [0 0.5 1];
app.UIAxes3.ZColor = [0.15 0.15 0.15];
app.UIAxes3.ZTick = [0 0.5 1];
app.UIAxes3.CameraPosition = [0.5 0.5 9.16025403784439];
app.UIAxes3.CameraTarget = [0.5 0.5 0.5];
app.UIAxes3.CameraUpVector = [0 1 0];
app.UIAxes3.Position = [366 1 300 185];
% Create StartanalysisButton
app.StartanalysisButton = uibutton(app.UIFigure, 'push');
app.StartanalysisButton.ButtonPushedFcn = createCallbackFcn(app, @StartanalysisButtonPushed, true);
app.StartanalysisButton.FontWeight = 'bold';
app.StartanalysisButton.FontColor = [0 0 1];
app.StartanalysisButton.Position = [40 550 100 22];
app.StartanalysisButton.Text = 'Start analysis';
end
end
methods (Access = public)
% Construct app
function app = app1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

  댓글 수: 0

로그인 to comment.

답변 수: 1

Hakob Bazoyan 님의 답변 18 Aug 2019

If you want to draw histogram on data, please try using histogram() function. Here's how I plot histogram in my application:
properties (Access = public)
HueHistogram matlab.ui.control.UIAxes; %UIAxis defined in application (UI)
end
methods (Access = public)
function DrawHistogram(obj)
% Below I'm using histogram function, and passing the axis
% object I have created in my application (HueHistogram)
% obj.Blocks.HueAvg is my data vector, 200 - is the number of bins
histo = histogram(HueHistogram, [obj.Blocks.HueAvg], 200);
end
end

  댓글 수: 0

로그인 to comment.



Translated by