Plots are stuck on semi-log axis

I have created an app that plots on UIAxes either with a plot command or semilogx command depending on a switch value. But once I have plotted with semilogx I am unable to revert to a linear x axis with subsequent executions of the code. The code snippet is shown below. The pasted image shows a bode response with points displayed with the red "x" called out in the regular plot command as opposed to the red "o" used in the semilogx command. I had set a breakpoint in the code and it clearly stopped in the 'Linear' case for every one of these plots. Why doesn't plot result in a linear x-axis?
% Plot results
switch app.FrequencyAxisSwitch.Value
case 'Linear'
plot(app.UIAxes2,fra_fvec(1:i_fra),mg21(1:i_fra),'rx');
plot(app.UIAxes3,fra_fvec(1:i_fra),ph21(1:i_fra),'rx');
case 'Logarithmic'
semilogx(app.UIAxes2,fra_fvec(1:i_fra),mg21(1:i_fra),'ro');
semilogx(app.UIAxes3,fra_fvec(1:i_fra),ph21(1:i_fra),'ro');
end

 Accepted Answer

I'm not sure you're going into the case you think you are, especially since the code for ylabel is not there so I can't tell which case you did. How/where are you setting the ylabel?
If you put a break point there at the switch, are you sure you're stepping into the linear one and doing the regular plot() call? What happens if you do this before the switch?
cla reset

3 Comments

Hi & thanks. The label was set in the code when the axes are created in the figure window. The axis labels are never changed after that point so I never have to re-label the axes.
I did have a break point at the switch and saw that the axes are re-plotted, but as semilogx, despite it being the Linear case. I'll try your suggestion for the cla reset next.
The snippet of code that creates the axes is shown below.
% Create UIAxes2
app.UIAxes2 = uiaxes(app.FrequencyResponseAnalyzerUIFigure);
title(app.UIAxes2, '')
xlabel(app.UIAxes2, 'Frequency - [Hz]')
ylabel(app.UIAxes2, 'Y')
app.UIAxes2.Visible = 'off';
app.UIAxes2.Position = [467 370 480 304];
% Create UIAxes3
app.UIAxes3 = uiaxes(app.FrequencyResponseAnalyzerUIFigure);
title(app.UIAxes3, '')
xlabel(app.UIAxes3, 'Frequency - [Hz]')
ylabel(app.UIAxes3, 'Y')
app.UIAxes3.Visible = 'off';
app.UIAxes3.Position = [467 27 480 299];
If the string is Linear and goes into the Log case, you might try casting everything to lower,
% Plot results
switch lower(app.FrequencyAxisSwitch.Value)
case 'linear'
plot(app.UIAxes2,fra_fvec(1:i_fra),mg21(1:i_fra),'rx');
plot(app.UIAxes3,fra_fvec(1:i_fra),ph21(1:i_fra),'rx');
case 'logarithmic'
semilogx(app.UIAxes2,fra_fvec(1:i_fra),mg21(1:i_fra),'ro');
semilogx(app.UIAxes3,fra_fvec(1:i_fra),ph21(1:i_fra),'ro');
end
or else use contains()
% Plot results
if contains(app.FrequencyAxisSwitch.Value, 'Linear', 'IgnoreCase', true)
plot(app.UIAxes2,fra_fvec(1:i_fra),mg21(1:i_fra),'rx');
plot(app.UIAxes3,fra_fvec(1:i_fra),ph21(1:i_fra),'rx');
else
semilogx(app.UIAxes2,fra_fvec(1:i_fra),mg21(1:i_fra),'ro');
semilogx(app.UIAxes3,fra_fvec(1:i_fra),ph21(1:i_fra),'ro');
end
If before those you put
whos app.FrequencyAxisSwitch.Value
what does it show in the command window? I want to make sure it's a character array, and not a number or something.
Bingo! We have a winner. Your original suggestion to use cla worked, but it is a little more complicated with handles. The plot and semilogx commands were in a loop in a section of code that is entered as a result of a callback from a pushbutton. I just needed to clear the axes prior to the loop. I did need to re-apply the label to the axes. Here is the code snippet with your suggestion.
cla(app.UIAxes2,'reset');% Answer 711488 "Image Analyst" suggestion
grid(app.UIAxes2,'on');
xlabel(app.UIAxes2, 'Frequency - [Hz]')
app.UIAxes2.Visible='on';
cla(app.UIAxes3,'reset');% Answer 711488 "Image Analyst" suggestion
grid(app.UIAxes3,'on');
xlabel(app.UIAxes3, 'Frequency - [Hz]')
app.UIAxes3.Visible='on';
switch app.OutputStyleSwitch.Value
case 'Real/Imaginary'
ylabel(app.UIAxes2,'Real')
ylabel(app.UIAxes3,'Imaginary')
case 'Magn(dB)/Phase(Deg)'
ylabel(app.UIAxes2,'Magnitude - [dB]')
ylabel(app.UIAxes3,'Phase - [Deg]')
end

Sign in to comment.

More Answers (0)

Categories

Find more on Labels and Styling in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!