Creating an interactive 3D bar graph
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!