Problem with xlim in setting the limit

I am using the code below. I want to set the limit of x from 6 to 16. But it is giving a error mentioned below. I have never encountered a error with xlim.
%%Error
"Index exceeds the number of array elements (2).
Error in Function_2D_LSF_Error_Estimator (line 83)
xlim([6 16])
%%Code
figure('DefaultAxesFontSize',20);
figure(1)
Iteration = (7:1:15);
B_0 = [0.5691 0.1838 0.1330 0.0687 0.0369 0.0365 0.0083 0.0038 0.0141];
SEEDT_B0 = plot(Iteration,B_0);
hold on
set(SEEDT_B0, ...
'LineStyle','none',...
'Color','#1b9e77',...
'LineWidth',1.5, ...
'Marker','s', ...
'MarkerSize',8, ...
'MarkerEdgeColor', '#1b9e77', ...
'MarkerFaceColor', '#1b9e77');
hold on
B_2 = [0.7520 0.2358 0.1073 0.0295 0.0118 0.0099 0.0118 0.0090 0.0065];
SEEDT_B2 = plot(Iteration,B_2);
hold on
set(SEEDT_B2, ...
'LineStyle','none',...
'Color','#d95f02',...
'LineWidth',1.5, ...
'Marker','d', ...
'MarkerSize',8, ...
'MarkerEdgeColor', '#d95f02', ...
'MarkerFaceColor', '#d95f02');
hold on
B_4 = [0.5769 0.1824 0.1488 0.0539 0.0359 0.0646 0.0651 0.0361 0.0484];
SEEDT_B4 = plot(Iteration,B_4);
hold on
set(SEEDT_B4, ...
'LineStyle','none',...
'Color','#7570b3',...
'LineWidth',1.5, ...
'Marker','o', ...
'MarkerSize',8, ...
'MarkerEdgeColor', '#7570b3', ...
'MarkerFaceColor', '#7570b3');
hold on
B_6 = [0.5113 0.3234 0.2645 0.1507 0.0912 0.0827 0.0547 0.0438 0.0444];
SEEDT_B6 = plot(Iteration,B_6);
hold on
set(SEEDT_B6, ...
'LineStyle','none',...
'Color','#e7298a',...
'LineWidth',1.5, ...
'Marker','>', ...
'MarkerSize',8, ...
'MarkerEdgeColor', '#e7298a', ...
'MarkerFaceColor', '#e7298a');
hold on
B_8 = [1.3808 0.8960 0.5848 0.1967 0.1902 0.0463 0.0440 0.0436 0.0452];
SEEDT_B8 = plot(Iteration,B_8);
hold on
set(SEEDT_B8, ...
'LineStyle','none',...
'Color','#66a61e',...
'LineWidth',1.5, ...
'Marker','*', ...
'MarkerSize',8, ...
'MarkerEdgeColor', '#66a61e', ...
'MarkerFaceColor', '#66a61e');
hold on
grid on
xlim([6 16])
hLegend = legend([SEEDT_B0 SEEDT_B2 SEEDT_B4 SEEDT_B6 SEEDT_B8],'b = 0','b = 2','b = 4','b = 6','b = 8','location','northeast');
set(gca,'XMinorTick','on','YMinorTick','on')
ax = gca;

4 件のコメント

Benjamin Thompson
Benjamin Thompson 2022 年 2 月 2 日
I am not seeing this with your code in R2021B Update 2, Windows 10. What MATLAB version and OS are you running on?
Ankush Kumar Mishra
Ankush Kumar Mishra 2022 年 2 月 2 日
I am using R2020A and Windows 10
Ankush Kumar Mishra
Ankush Kumar Mishra 2022 年 2 月 2 日
Thanks it got resolved. I just closed and started matlab again and it worked. Don't know how.
Steven Lord
Steven Lord 2022 年 2 月 2 日
You likely had created a variable named xlim previously. In that case, executing that script file would have tried to index into that variable instead of calling the xlim function.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

タグ

質問済み:

2022 年 2 月 2 日

コメント済み:

2022 年 2 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by