Hello,
I am trying to use xlim to limit my x-axis
h_to_plot = linspace(1,20,20);
horizon = 1:1:20;
quant = 1.64;
mat = [coefficients ses [1:1:20]'];
[~,idx] = sort(mat(:,1));
sortedmat = mat(idx,:);
figure(3)
errorbar(horizon(h_to_plot),sortedmat(h_to_plot,1),quant*sortedmat(h_to_plot,2),'o','Linewidth',2)
hold on
xlim = ([0 20.5])
However, I could not make x-axis starts from 0 to 20.5
Is there any way I could use xlim to extend my x axis to 20.5?
Thanks

 採用された回答

VBBV
VBBV 2021 年 12 月 3 日

0 投票

xlim([0 20.5]) % difference
Difference in using and = between the xlim and parenthesis

5 件のコメント

Ajay S
Ajay S 2022 年 12 月 26 日
bruh can you please make it a bit more clear
Simon
Simon 2025 年 2 月 12 日
xlim([0 20.5]) is correct
xlim = ([0 20.5]) is incorrect
Steven Lord
Steven Lord 2025 年 2 月 12 日
The command:
xlim = ([0 20.5])
xlim = 1×2
0 20.5000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
creates a variable named xlim. While that variable exists, attempts to call the xlim function in that context will instead be interpreted as an attempt to index into that variable. For example, if I try to then set the limits to the vector [-1 1] using the xlim function, MATLAB will throw an error since there's no such thing as the -1st element of an array in MATLAB:
xlim([-1 1])
Array indices must be positive integers or logical values.

xlim appears to be both a function and a variable. If this is unintentional, use 'clear xlim' to remove the variable 'xlim' from the workspace.
Paul
Paul 2025 年 2 月 12 日
I don't think I've ever seen this error message before idenitfying the ambiguity between the variable and the function. Is that new?
Is there any overhead incurred by Matlab having to determine the xlim is also a function in this case?
Would it also indicate if xlim is some other useful thing, like an .m file or .slx file or a class definition?
DGM
DGM 2025 年 2 月 13 日
This is a common mistake, and future readers should make sure that the variable that they mistakenly created gets cleared, otherwise the error will persist even after the code is fixed.
clear xlim

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2021 年 12 月 3 日

コメント済み:

DGM
2025 年 2 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by