Error with Set function when I am trying to change the Xlabel form a figure (Unable to use a value of type matlab.ui.Figure as an index.)

조회 수: 12 (최근 30일)
I am getting an error in the Set function. I have been trying to solve the problem but havent been able to get through. In plamce of 'figure(1)', I also tried gca but it showed the same error. (Unable to use a value of type matlab.ui.Figure as an index.)

채택된 답변

Guillaume
Guillaume 2020년 3월 11일
Rather than giving us a screenshot of the code, which we can't copy and edit, paste your code directly in your question. Also it would be very useful to have the full text of the error message, not your interpretation of it.
Rather than using gcf or gca get the figure handle when your create it:
hfig = figure(1);
%... then use hfig everywhere you used gcf or fig
Further on, your code attempts to set the 'XScale' property on a figure but XScale is not a figure property. Possibly you meant
set(hfig.CurrentAxes, 'XScale', 'linear', 'YScale', 'linear');
which you could also write as:
hfig.CurrentAxes.XScale = 'linear';
hfig.CurrentAxes.YScale = 'linear';

추가 답변 (2개)

Steven Lord
Steven Lord 2020년 3월 11일
Rename the variable you've created in your workspace named set.
You intended to call the set function included in MATLAB on the line "set(figure(1), 'XScale', 'linear', 'YScale', 'log')" but because the variable exists MATLAB interpreted that as an attempt to index into the variable. MATLAB doesn't know how to use a figure handle as an index into a variable so it throws an error.
You should also use a handle to an axes instead of a figure to set the XScale and YScale properties since those are axes properties not figure properties, as tmarske and Guillaume stated, but you need to remove the variable named set as well.

tmarske
tmarske 2020년 3월 11일
XScale and ySCale are properties of the axes, not the figure, so you need to pass an axes handle in as the first argument to set(). Try:
set(ax, 'XScale', 'linear', 'YScale', 'linear')

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by