App Designer Axis Issue xlim and dataticks

I want to create axis (X,Y) with dateticks.
I want to plot the data with axis(xlim and dateticks - hh:mm:ss.SSS) but I am getting an error
Edited
ans =
101×1 duration array
00:00:46.000
00:00:46.000
00:00:46.000
00:00:46.000
00:00:46.000
00:00:47.000
00:00:50.000
00:00:50.000
00:00:50.000
00:00:50.000
00:00:50.000
00:00:50.000
00:00:50.000
00:00:50.000

2 Commenti

Adam Danz
Adam Danz il 22 Nov 2019
Modificato: Adam Danz il 28 Gen 2020
Check out your values of xstart xend. Then look at the error message and ask yourself what requirements you're not fulfilling. There are 3 requirements according to the error message.
  • "Value must be a 1x2 vector
  • of numeric type
  • in which the second element is larger than the first and may be Inf"
To address the 1st point, size([xstart xend]); is that 1x2?
To address the 2nd point, class(xstart) and class(xend); is it numeric?
To address the 3rd point, xend>xstart; is it true?
NOTE: The user "Matlab" has deleted their comments within this discussion.
Adam Danz
Adam Danz il 25 Nov 2019
Modificato: Adam Danz il 25 Nov 2019
  1. Sorry, xstart and xend should each be 1x1. The [xstart, xend] should be 1x2 which looks OK in your data above.
  2. If your x-data are duration, your x-limits need to be durations, too. That's directly from the documentation. "You can specify the limits as numeric, categorical, datetime, or duration values. However, the type of values that you specify must match the type of values along the x-axis."
  3. The 2nd value of your x-axis limit must be greater than your first value. That makes sense because you're setting the [lower, upper] bounds of the x-axis.
So you need to fix #2 and #3. My answer has a function demo.

Accedi per commentare.

 Risposta accettata

Adam Danz
Adam Danz il 25 Nov 2019
Modificato: Adam Danz il 27 Nov 2019
I see your data are durations along the x axis. To set the axis limits,
  1. Use xlim() where the first input is your axis handle and your 2nd input is a [1 x 2] vector of durations
  2. The 2nd value of your x limit must be larger than the first value
Here's a demo
% Create data and plot it on UIAxes
h = duration([9 17 54;12 32 3]);
app.uiax = uiaxes();
plot(app.uiax,h,[0,1], '-o')
% Create the [start,end] x-limits
xstart = duration(9,0,0);
xend = duration(13,0,0);
% Set the x limits: xend must be larger than xstart
xlim(app.uiax,[xstart, xend])
If your are plotting this : [c{range,1},range]
then you minimum and maximum durations would be
xstart = min([c{range,1},range]);
xend = max([c{range,1},range]);

6 Commenti

Adam Danz
Adam Danz il 25 Nov 2019
Modificato: Adam Danz il 28 Gen 2020
Please copy-paste the following values so I can see exactly what they are:
  1. xstart
  2. xend
  3. The data you're plotting: plot([c{range,1},range],'r-sq'), so, I'd like to see [c{range,1},range]
NOTE: The user "Matlab" has deleted their comments within this discussion.
1. I see nothing wrong with those values. This works fine for me.
Did you take that screenshot before or after applying xlim()? What problems are you having?
% Create the [start,end] x-limits
xstart = duration(0,0,0);
xend = duration(720,0,0);
% Set the x limits: xend must be larger than xstart
xlim(app.uiax,[xstart, xend])
2. Your range values in your comment above look like they are numbers (double?), not durations. But in your question, your range values look like durations. Did something change?
3. " xend has a bug ..I don't know where High number for hour duration comes from"
You have to investigate why xend has that value. You have the code, you have the inputs, so all you need to do look at the values in your code to determine why xend is 720.
4. " I observe frequent crash of GUI since the introduction of the app.UIAxes = uiaxes()"
Don't just copy-paste code into your file. Take 5 minutes to think about the code. What is it doing? In the demo I shared, I needed to create UIAxes. You don't need to create UIAxes because your app already has them. So that line of code shouldn't be in your app.
% Create data and plot it on UIAxes *
h = duration([9 17 54;12 32 3]); * This section creates a plot for my demo
app.uiax = uiaxes(); *
plot(app.uiax,h,[0,1], '-o') *
% Create the [start,end] x-limits
xstart = duration(9,0,0);
xend = duration(13,0,0);
% Set the x limits: xend must be larger than xstart
xlim(app.uiax,[xstart, xend])
" It seems loading [ old data & new data] without clearvars is creating vague value. "
Where are you loading the data? I don't see load() in your code.
Also, I don't see where this variable is in your code: updateAppLayout
More importantly, I've lost track of what that problem is we're trying to solve. We started with the xlim() and datetime values and now it seems you're having trouble loading data?
Maybe you could reframe the problem.
I see. Glad we got the datetick xlim problem worked out.
It looks like you've got a list of additional problems that are unrelated. Maybe it would be better to solve one at a time and to make a new question since it's a new topic. I'd be glad to help but tackling all of these within the same thread could make it difficult to follow the discussion. You could copy the link below to bring the new thread to my attention, if you'd like.
Thanks a lot.
Issue : How to make a plot a figure from stackedplot ?
Others I will raise the new threads.
Hi Adam,
Can you please have a look in the below post.
The issue is initiail text data are over lapping . I would like to have a Tab like implementation before next data is printed.
Example : Issue can be seen with below example, One,Two and Three text are over lapping.
x = [1:3];
y = [1:3];
str1 = ['One'];
str2 = ['Two'];
str3 = ['Three'];
plot(x,y)
text(x,y,str1);
text(x,y,str2);
text(x,y,str3);
Thank you

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by