Assign XLabel, YLabel from variable, fix YLim

조회 수: 5 (최근 30일)
matthias82
matthias82 2018년 3월 19일
편집: Julian Hapke 2018년 3월 19일
Hi, I've got problems with the figure, plot and axes functions and handles.
Some variables already exist in the workspace prior to this script which I import and I want to plot. Var1, Var2: type char x1 and y1 are the data matrices anyways.
Here's the code first:
h_fig1 = figure(1);
h_fig1.Name = [Var1, ' vs. ',Var2];
h_ax1 = axes;
h_ax1.YLimMode = 'manual';
h_ax1.YLim = [50,60];
h_ax1.YLimSpec = 'tight';
h_ax1.XLabel = Var1;
h_ax1.YLabel = Var2;
h_plot1 = plot(h_ax1,x1,y1);
What I desire to do: 1. Label the axes according to the CHAR variables above. I tried to convert to string before - didn't work either. Whatever, MatLAB returns the following error:
"While setting property 'XLabel' of class 'Axes':
Value must be 'matlab.graphics.Graphics'.
Error in Plot_fct(line 17)
h_ax1.XLabel = Var1;"
2. Set the limit of Y fixed from 50 to 60. Yet when I append the plot function afterwards and the plot function finds data below or above the limit, it seems to ignore the limits and spread the YLim above the entire range. How can I really fix the Axis limits? I tried to append "tight", but that didn't help either.
Thanks, Matts

답변 (1개)

Julian Hapke
Julian Hapke 2018년 3월 19일
편집: Julian Hapke 2018년 3월 19일
doc xlabel
Edit: extented explanation: ax_handle.XLabel returns a handle for the label. This object has a property named "String", which can be used to change the displayed string.
For the second Question: As long as the ax_handle.YLimMode == 'manual', the plot should not change when
hold on
was set. If you just plot into the same axis again, it is recalculated and the properties are reset, if you set
ax_handle.NextPlot = 'replacechildren'
the limits are maintained.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by