Custom Object using plot toolbar

조회 수: 10 (최근 30일)
Joel Newman
Joel Newman 2019년 7월 17일
댓글: Ganesh Regoti 2019년 8월 8일
I am designing a class and I want the user to be able to use the built in plotting tools in the PLOTS toolbar.
What I have tried:
  • object converter to double.
  • implemting a plot function
While I know I can define my own GUI or just have the user use the plot() command I would like to have the applicable built in graph types be selected in the PLOTS toolbar.
Sample Code:
classdef classA < handle
properties
data double
other_stuff
end
methods
function obj = classA()
obj.data = [1,2,3,4,5];
obj.other_stuff = 'Something';
end
function result = double(obj)
result = obj.data;
end
function h = plot(obj)
h = plot(obj.data);
end
end
end
Calling Code:
a = classA();
The plots in the tab do not show up.

답변 (1개)

Ganesh Regoti
Ganesh Regoti 2019년 7월 29일
The PLOTS gallery shows the built-in plots that are suitable for the selected variables from the workspace. But a class object encapsulates various properties along with methods in it. So, whenever a class object is selected, there are no graphs in PLOTS gallery that can plot a class object.
  댓글 수: 2
Joel Newman
Joel Newman 2019년 8월 7일
Thanks for your response.
when the first icon (generic plot) is selected it seems like its just a shortcut to type plot([selected variable]) in the command window. Is there some more reading that I can do to see what to extend or inherit from to enable the built in plots? Is it really just as simeple as if you have an object there is no possible way to enable that for the PLOTS gallery.
I am fine spending the time implementing all of the overloaded plotting functions if that is what it takes.
Ganesh Regoti
Ganesh Regoti 2019년 8월 8일
Hi Joel,
If you want to implement all the built-in plots for your class object, you can overload the functions and following link can help you in writing code for all the built-in plots
Why we cannot access PLOTS gallery with class object?
A class object follows all the specifications of OOP and one of the specifications is Data Hiding, data is only visible to the object but not to external environment. So, PLOTS gallery cannot suggest any plot as it does not see any data.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by