Cannot set axes properties

4 views (last 30 days)
Angle Qian
Angle Qian on 30 Apr 2018
Commented: dpb on 30 Apr 2018
I am trying to set axes properties.
clc;
length = 10;
k = linspace(1, length, length);
m = 100;
p = 0.95;
temp1 = - (k.^(-1));
temp2 = log(1-p);
temp3 = temp2.*temp1;
temp4 = exp(temp3);
y = (1+temp4).*(0.5*m);
err = (temp4-1).*(0.5*m);
pointEstimator = (1+(k.^(-1))).*m;
width = 12;
height = 10;
AxesLineWidth = 0.75;
FotSize = 8;
LineWidth = 1.5;
MarkerSize = 6;
pos = get(gcf, 'Position');
set(gcf, 'Position', [pos(1) pos(2) width*100 height*100]);
errorbar(k, y, err,'LineWidth',LineWidth,'LineStyle','none','Color',[153,142,195]/255); hold on;
plot(k, pointEstimator,'o','MarkerEdgeColor',[241,163,64]/255,'MarkerFaceColor',[241,163,64]/255,'MarkerSize',MarkerSize); hold on;
set(gca, 'LineWidth',AxesLineWidth,'FontSize',15,'TickLabelInterpreter','latex');
xlim([0 length+0.5]);
max = 1 / (1-p) * m;
ymax = max * 1.05;
ylim([0 ymax]);
xlabel('$$ k $$','Interpreter','latex','FontSize',15);
ylabel('Estimated $$ N $$','Interpreter','latex','FontSize',15);
yticks([m 5*m 10*m 15*m 20*m 25*m]);
yticklabels({'$$m$$', '$$5m$$', '$$10m$$', '$$15m$$', '$$20m$$', '$$25m$$'});
grid on;
grid minor;
legend('95% Confidence Intervals','Point Estimators');
However, an error occurs.
Error using set
Conversion to double from struct is not possible.
Error in plot1 (line 32)
set(gca, 'LineWidth',AxesLineWidth,'FontSize',15,'TickLabelInterpreter','latex');
Any help or suggestions will be appreciated!
  2 Comments
Star Strider
Star Strider on 30 Apr 2018
Your code runs for me without error in R2018a.
Also, length is a core MATLAB function you may want to use later, so rename it to something else. (Naming a variable the same as a MATLAB function is known as ‘overshadowing’, and is best avoided.) I chose to rename it ‘len’:
len = 10;
k = linspace(1, len, len);
...
xlim([0 len+0.5]);
dpb
dpb on 30 Apr 2018
Not same code as created the error; this was in some function plot1 by the error message text.
The above code works fine.
Looks like you've somehow during debugging/testing gotten a dot (period) and subsequent field name added to the AxesLineWidth variable in the actual code that silently turned it into a struct. Do a
clear Axes*
and try again...or if you don't have much data in the workspace that would be difficult to recreate, just
clear
to start over from clean slate.

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!