Creating an interactive 3D bar graph
2 views (last 30 days)
Show older comments
Daniel Rayleigh
on 29 Nov 2015
Commented: Daniel Rayleigh
on 30 Nov 2015
Hi, I've been struggling to create a 3D interactive bar graph.
I have the following code based off the example I found online (Here http://www.mathworks.com/help/control/ug/build-app-with-interactive-plot-updates.html)
phase = 0; % a value between 0 and 2 pi
amp = 0; % a value between 0 and 1
A(1:6,1:6) = amp; % a 6x6 matrix of with all elements set to amp
sys = CreateHologram(A,phase,4); %this is a separate method that returns an (NxM) matrix with the element at (i,j) equal to a value between 0 and 255
f = figure;
ax = axes('Parent',f,'position',[0.13 0.39 0.77 0.54]);
colormap( ColourMap() ); % a custom colourmap
h = bar3(ax,sys); % this is a 3D bar graph
for k = 1:length(h) %The following for loop assigns bar colour based on their height
zdata = get(h(k),'ZData');
set(h(k),'CData',(zdata),'FaceColor','interp');
end
b = uicontrol('Parent',f,'Style','slider','Position',[81,100,419,23],'value',amp, 'min',0, 'max',1); % a
slider
b2 = uicontrol('Parent',f,'Style','slider','Position',[81,50,419,23],'value',phase, 'min',0, 'max',2*pi); % a slider
bgcolor = [0,1,1];
bl8 = uicontrol('Parent',f,'Style','text','Position',[50,54,23,23],'String','0','BackgroundColor',bgcolor);
bl9 = uicontrol('Parent',f,'Style','text','Position',[500,54,23,23],'String','1','BackgroundColor',bgcolor);
bl10 = uicontrol('Parent',f,'Style','text','Position'[240,75,100,23],
'String','Phase','BackgroundColor',bgcolor);
bl11 = uicontrol('Parent',f,'Style','text','Position',[240,20,100,23],'String','Intensity','BackgroundColor',bgcolor);
bl12 = uicontrol('Parent',f,'Style','text','Position',[50,100,23,23],'String','0','BackgroundColor',bgcolor);
bl13 = uicontrol('Parent',f,'Style','text','Position',[500,100,23,23],'String','2pi','BackgroundColor',bgcolor);
set(b,'Callback',@(es,ed) updateSystem(h, CreateHologram(A,get(es,'Value'),4) ));
So far the code executes correctly once and draws the graph with the intial values for phase and amp but as soon as I try to adjust either of the sliders the following error is generated: Undefined function 'updateSystem' for input arguments of type 'double'.
Any help is greatly appreciated
0 Comments
Accepted Answer
Geoff Hayes
on 30 Nov 2015
Daniel - have you written the callback updateSystem? The error message is telling you that the function is either undefined or it cannot be found within the MATLAB search path.
You made a reference to an example that makes use of the updateSystem function which is part of the Control System Toolbox (see update dynamic system data in a response plot for details). Do you have this toolbox? In the MATLAB Window type
ver
to list your version of MATLAB and all toolboxes that you have installed. If you don't have the toolbox (or the version that includes this function) then you will need to find an alternative.
More Answers (0)
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!