xlim function error. i have seen on video, the codes were working but with me it is not working
古いコメントを表示
**My codes are below. I get that error: "Error using xlim (line 31) Limits must be a 2-element vector of increasing numeric values."
Also xtickformat function gives me eror. Can you help me? Thanks**
clc; clear; close all;
dates=datetime(2025,8,17)+calmonths(2:11)+calweeks(0:9)
xlim(datetime([2025 2026],[11 5],[12 23]))
xtickformat('dd-MMM-yyyy')
採用された回答
その他の回答 (1 件)
I would expect to see that error if you'd plotted with non-datetime data as your X data. If for example you'd plotted these points:
x = 1:10;
y = x.^2;
plot(x, y)
How much of that plot would you expect to see if I set the X limits from last Thursday to next Saturday?
T = datetime('today');
lastThursday = dateshift(T, 'dayofweek', 'Thursday', 'previous')
nextSaturday = dateshift(T, 'dayofweek', 'Saturday', 'next')
plot(x, y)
xlim([lastThursday, nextSaturday]);
You haven't specified what error message you received when you tried calling xtickformat but I'm guessing the root cause is the same: you can't change numbers on the X axis into dates and times.
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

