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.)

11 次查看(过去 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 中查找有关 Data Exploration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by