Effacer les filtres
Effacer les filtres

Plotting on matlab app panel does not update the tick labels but it overlaps them

4 vues (au cours des 30 derniers jours)
I'm trying to plot a preview of a signal on a uipanel in a matlab app. What happens is that the first time you preview it everything works fine since there is no pre existent plot under it. The second time you preview it the graph updates correctly but the axes tick label don't, meaning that it both keeps the old ones and displays the new ones overlapped.
The preview is called via push button and the plot is done using uipanel axes.
This is a walkthrough of what happens:
First time preview selecting signal and applying ->
Result is fine ->
Now i choose a different signal with a different axis lenght (300 instead of 1000) and preview it ->
As you can see the plot is fine regarding the line but the axis overlap/don't update/don't render correctly.
This is the code in the app which basically updates and simulates the underlying simulink (this works well) and calls an external function in a class to display the preview. This section is not really where the problem lies, i share just out of context.
% Button pushed function: InputApplyButton
function InputApplyButtonPushed(app, event)
%gather values from gui
app.inputType=app.InputshapeDropDown.Value;
app.inputPanelAxes=axes(app.InputPreviewPanel);
switch true
case strcmp(app.inputType,'Ramp')
%ramp parameters
set_param('TCASim/InputType','Value','3'); %switch
set_param('TCASim/Ramp','Slope',num2str(app.SlopeEditField.Value));
set_param('TCASim/Ramp','InitialOutput',num2str(app.InitialOutputEditField.Value));
app.inPrev=toleranceChain.inputPreview(app.inputType,app.inputPanelAxes,...
app.SlopeEditField.Value,app.InitialOutputEditField.Value);
case strcmp(app.inputType,'Chirp')
%chirp parameters
set_param('TCASim/InputType','Value','2'); %switch
set_param('TCASim/Chirp','f1',num2str(app.InitialFrequencyEditField.Value));
set_param('TCASim/Chirp','T',num2str(app.TargetTimeEditField.Value));
set_param('TCASim/Chirp','f2',num2str(app.FrequencyatTargetTimeEditField.Value));
set_param('TCASim/ChirpGain','Gain',num2str(app.ChirpAmplitudeEditField.Value));
app.inPrev=toleranceChain.inputPreview(app.inputType,app.inputPanelAxes,...
app.InitialFrequencyEditField.Value,app.TargetTimeEditField.Value,app.FrequencyatTargetTimeEditField.Value,...
app.ChirpAmplitudeEditField.Value);
case strcmp(app.inputType,'Other')
%Other parameters
set_param('TCASim/InputType','Value','1'); %switch
set_param('TCASim/Other','WaveForm',app.WaveformDropDown.Value);
set_param('TCASim/Other','Amplitude',num2str(app.AmplitudeEditField.Value));
set_param('TCASim/Other','Frequency',num2str(app.FrequencyEditField.Value));
app.inPrev=toleranceChain.inputPreview(app.inputType,app.inputPanelAxes,...
app.WaveformDropDown.Value,app.AmplitudeEditField.Value,app.FrequencyEditField.Value);
end
app.InputPreviewPlaceholder.Visible='off';
app.FullScreenInputPreview.Enable='on';
end
This is the actual preview function:
function prev=inputPreview(inputType,plotAxes,varargin)
prevTime=1:0.1:100;
switch true
case strcmp(inputType,'Ramp')
%1 is slope, 2 is initial output
y = prevTime*varargin{1} + varargin{2};
prev=plot(plotAxes,y);
case strcmp(inputType,'Chirp')
%1 is initial freq, 2 is target time, 3 is freq at
%target tim, 4 is amplitude/gain
y=varargin{4}*chirp(0:varargin{2},varargin{1},varargin{2},varargin{3});
prev=plot(plotAxes,y);
case strcmp(inputType,'Other')
%1 is wave form,2 is amplitude, 3 is freq
switch true
case strcmp(varargin{1},'sine')
y=varargin{2}*sin(varargin{3}*prevTime);
prev=plot(plotAxes,y);
case strcmp(varargin{1},'square')
y=varargin{2}*square(varargin{3}*prevTime);
prev=plot(plotAxes,y);
case strcmp(varargin{1},'sawtooth')
y=varargin{2}*sawtooth(varargin{3}*prevTime);
prev=plot(plotAxes,y);
case strcmp(varargin{1},'random')
y=varargin{2}*rand(1,length(1:varargin{3}:100));
prev=plot(plotAxes,y);
end
end
end
This is what i already tried:
  • cla reset and all its combinations
  • set(..., 'XTicks',{}) and all its combinations
  • set(...,'XTicksLabels',{}) and all its combinations
  • drawnow
  • refreshappdata
  • refreshdata
I lost countless hours on this, any idea would really help. I'm also up to change the whole plotting system if needed.
Update: i have the same setup, in the same app with the same code but not placed inside a tab group and it works perfectly without issue. I'm baffled.

Réponses (1)

Benjamin Kraus
Benjamin Kraus le 1 Sep 2023
You did not share all the code of your app, but based on your pictures, the issue looks like you are creating multiple axes, and those axes are all overlapping each other.
My guess is that somewhere in your app you are calling either the axes or uiaxes command, which is creating a new axes that overlaps the previous axes. Instead, you should be reusing the existing axes, and if necessary calling cla to clear the axes (remove existing data) before reusing it.
For example, this code will create two overlapping axes with different ticks, which is why you see a wierd collection of ticks:
f = figure;
ax1 = axes(f);
plot(ax1, sin(1:10))
ax2 = axes(f);
plot(ax2, 1:13);
Alternatively, instead of calling axes (or uiaxes) twice, you can use cla to clear the axes and reuse it, like this:
f = figure;
ax1 = axes(f);
plot(ax1, sin(1:10))
cla(ax1)
plot(ax1, 1:13);

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by