Thread Subject: Bar plot in Guide GUI, axis problems

Subject: Bar plot in Guide GUI, axis problems

From: Todd Welti

Date: 22 Nov, 2011 19:39:08

Message: 1 of 3

I have a GUI under development. Fairly advanced, with multiple tabs, etc, and made using Guide. I'm wanting to put a "Volume Meter" on it, that runs in realtime, displaying signal levels from the sound card. I have a timer callback that updates the plot. So, the update function is called 4 times a second, and it grabs data from the sound card, calculates the values to display and updates the plot in hte GUI. I'm using a bar plot. I set the 'NextPlot' value to 'UpdateChildren' in Guide editor so (I hoped) the axis props would not be reset each time new data is plotted.

The data from the card is betwee 0 and 1, converted to dB, so between -Inf (practically speaking around -110) and 0 dB. To make it plot the way I want (like a VU meter, with the bars coming up from the bottom), I added 110 to the data stream and set the YLim property to [0 110]. I set the Yticks to [0 20 40 60 80 90 100 110], and Ylabels to [-110 -90 -70 -50 -30 -20 -10 0], and both set to 'Manual'. Ylim mode also set to manual.

I should also mention that I am plotting two types of data (rms and peak) for left/right/and left+right channels. SO, that means I am constructing a data matrix to use in the bar() plot call. That means there are multiple barseries (I did do a test of just plotting a single value and the problem persists though - so I don't think this is the issue).

When the GUI figure is initially generated, the Y limits look as desired. BUT, when the first data is plotted, the y limits are changed - for example to -110 to -70. Additionally, the bar plots that DO show up don't exactly match the actual values that are being plotted. I have tried adding code to try to manually set the limits, which either have no effect, or I'm getting strange error messages, or other unintended results. The callback code is listed below, some of the things I tried to fix this are shown remmed out. Any help is appreciated, I seem to be in over my head here.

function UpdateMeter(hObject, event, handles)
% SPLmeterAxis is the Tag for the axis in the GUI

% get audio data
[Audiodata absrecposition overflow cstarttime]= PsychPortAudio('GetAudioData', handles.pahandle);
% calculate rms and peak values for Left, Right, and Left/Right mean channels
Audiodata = Audiodata';
rms = 20.*log10((sqrt(mean(Audiodata.^2))));
peak = 20.*log10(max(abs(Audiodata)));
LRmean = 20.*log10(sqrt(mean(mean(Audiodata.^2))));

% generate plotting matrix, adding 110 to the data to match manually set y limits, in order to %% get desired bar plots coming up from the bottom of the plot.
plotdat = [peak(1) rms(1);peak(2) rms(2);NaN LRmean ] +110



% PLOT

% axis(handles.SPLmeterAxis,'manual')
h=bar(handles.SPLmeterAxis, plotdat,1);
set(h(1),'facecolor','red','linewidth',1) %this shouldn't be needed but apparently it is!

%%these do nothing or generate errors
% set(h,'YLim',[0,110],'YLimMode','manual')
% set(handles.SPLmeterAxis,'YLim',[0,110],'YLimMode','manual')
% axis(handles.SPLmeterAxis,[0 4 0 110])

%%both of these generate a new axis and error about vector needing 2, 4, or 6 elements (?!)
% axis(h(1),[0 4 -110 0])
% axis(h,[0 4 -110 0])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Platform is WinXP, Matllab 7.12.0

Subject: Bar plot in Guide GUI, axis problems

From: Todd Welti

Date: 22 Nov, 2011 20:47:08

Message: 2 of 3

Checking further, it seems that the 'YTick' is being reset to [0 50 100] each time a new plot is made. But it shouldn't be, if 'nextplot' is 'replacechildren'.

Subject: Bar plot in Guide GUI, axis problems

From: Steven_Lord

Date: 28 Nov, 2011 15:22:16

Message: 3 of 3



"Todd Welti" <twelti@harman.com> wrote in message
news:jah1oc$r48$1@newscl01ah.mathworks.com...
> Checking further, it seems that the 'YTick' is being reset to [0 50 100]
> each time a new plot is made. But it shouldn't be, if 'nextplot' is
> 'replacechildren'.

What are the values of the YLimMode and YTickMode properties of the axes?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
guide Todd Welti 22 Nov, 2011 14:39:11
gui Todd Welti 22 Nov, 2011 14:39:11
bar Todd Welti 22 Nov, 2011 14:39:11
plot Todd Welti 22 Nov, 2011 14:39:11
axis Todd Welti 22 Nov, 2011 14:39:11
problems Todd Welti 22 Nov, 2011 14:39:11
rssFeed for this Thread

Contact us at files@mathworks.com