Cannot set text to UIaxes because cannot set position since xaxis is made of datetime
I have an application that plots time against pressure values. Time is of the format datetime. I plot using these lines of code.
plot(app.UIAxes_9,pressureTime,Pressure);
app.UIAxes_9.XGrid ="on";
app.UIAxes_9.XMinorGrid ="on";
app.UIAxes_9.YGrid ="on";
app.UIAxes_9.YMinorGrid ="on";
app.UIAxes_9.LineWidth = 2;
app.UIAxes_9.XLabel.String = ‘Time&Date’;
app.UIAxes_9.XLabel.FontSize = 12;
app.UIAxes_9.XLabel.FontWeight ="bold";
app.UIAxes_9.YLabel.String = ‘Pressure[bar]’;
app.UIAxes_9.YLabel.FontSize = 12;
app.UIAxes_9.YLabel.FontWeight ="bold";
app.UIAxes_9.Title.String = ‘Pressure Cycle’;
app.UIAxes_9.Title.FontSize = 14;
app.UIAxes_9.Title.FontWeight ="bold";
[maxValue, maxIndex] = max(Pressure);
maxY = Pressure(maxIndex);
maxX = pressureTime(maxIndex);
text1 = ‘Max Pressure[bar]: ‘;
text2 = num2str(maxValue);
finalText = strcat(text1,text2);
text(‘Parent’,app.UIAxes_9,’String’,finalText,’HorizontalAlignment’, ‘left’,’VerticalAlignment’,’bottom’,’Position’,[maxX maxY]);
The problem is the last line, where I tried to put a text on the UIAxes. That is
text(‘Parent’,app.UIAxes_9,’String’,finalText,’HorizontalAlignment’, ‘left’,’VerticalAlignment’,’bottom’,’Position’,[maxX maxY]);
where I tried to set the position of the text at maxX and maxY. But [maxX maxY] is giving me an error :
Error using datetime/horzcat (line 1468)
All inputs must be datetimes or date/time character vectors or date/time strings.
So what I understood is you cant combine a double and datetime to form an array. So how can I do this for a app.UIaxes. For a normal plot it is easy, but here I need for app.UIaxes. How to do this. Thank you.I have an application that plots time against pressure values. Time is of the format datetime. I plot using these lines of code.
plot(app.UIAxes_9,pressureTime,Pressure);
app.UIAxes_9.XGrid ="on";
app.UIAxes_9.XMinorGrid ="on";
app.UIAxes_9.YGrid ="on";
app.UIAxes_9.YMinorGrid ="on";
app.UIAxes_9.LineWidth = 2;
app.UIAxes_9.XLabel.String = ‘Time&Date’;
app.UIAxes_9.XLabel.FontSize = 12;
app.UIAxes_9.XLabel.FontWeight ="bold";
app.UIAxes_9.YLabel.String = ‘Pressure[bar]’;
app.UIAxes_9.YLabel.FontSize = 12;
app.UIAxes_9.YLabel.FontWeight ="bold";
app.UIAxes_9.Title.String = ‘Pressure Cycle’;
app.UIAxes_9.Title.FontSize = 14;
app.UIAxes_9.Title.FontWeight ="bold";
[maxValue, maxIndex] = max(Pressure);
maxY = Pressure(maxIndex);
maxX = pressureTime(maxIndex);
text1 = ‘Max Pressure[bar]: ‘;
text2 = num2str(maxValue);
finalText = strcat(text1,text2);
text(‘Parent’,app.UIAxes_9,’String’,finalText,’HorizontalAlignment’, ‘left’,’VerticalAlignment’,’bottom’,’Position’,[maxX maxY]);
The problem is the last line, where I tried to put a text on the UIAxes. That is
text(‘Parent’,app.UIAxes_9,’String’,finalText,’HorizontalAlignment’, ‘left’,’VerticalAlignment’,’bottom’,’Position’,[maxX maxY]);
where I tried to set the position of the text at maxX and maxY. But [maxX maxY] is giving me an error :
Error using datetime/horzcat (line 1468)
All inputs must be datetimes or date/time character vectors or date/time strings.
So what I understood is you cant combine a double and datetime to form an array. So how can I do this for a app.UIaxes. For a normal plot it is easy, but here I need for app.UIaxes. How to do this. Thank you. I have an application that plots time against pressure values. Time is of the format datetime. I plot using these lines of code.
plot(app.UIAxes_9,pressureTime,Pressure);
app.UIAxes_9.XGrid ="on";
app.UIAxes_9.XMinorGrid ="on";
app.UIAxes_9.YGrid ="on";
app.UIAxes_9.YMinorGrid ="on";
app.UIAxes_9.LineWidth = 2;
app.UIAxes_9.XLabel.String = ‘Time&Date’;
app.UIAxes_9.XLabel.FontSize = 12;
app.UIAxes_9.XLabel.FontWeight ="bold";
app.UIAxes_9.YLabel.String = ‘Pressure[bar]’;
app.UIAxes_9.YLabel.FontSize = 12;
app.UIAxes_9.YLabel.FontWeight ="bold";
app.UIAxes_9.Title.String = ‘Pressure Cycle’;
app.UIAxes_9.Title.FontSize = 14;
app.UIAxes_9.Title.FontWeight ="bold";
[maxValue, maxIndex] = max(Pressure);
maxY = Pressure(maxIndex);
maxX = pressureTime(maxIndex);
text1 = ‘Max Pressure[bar]: ‘;
text2 = num2str(maxValue);
finalText = strcat(text1,text2);
text(‘Parent’,app.UIAxes_9,’String’,finalText,’HorizontalAlignment’, ‘left’,’VerticalAlignment’,’bottom’,’Position’,[maxX maxY]);
The problem is the last line, where I tried to put a text on the UIAxes. That is
text(‘Parent’,app.UIAxes_9,’String’,finalText,’HorizontalAlignment’, ‘left’,’VerticalAlignment’,’bottom’,’Position’,[maxX maxY]);
where I tried to set the position of the text at maxX and maxY. But [maxX maxY] is giving me an error :
Error using datetime/horzcat (line 1468)
All inputs must be datetimes or date/time character vectors or date/time strings.
So what I understood is you cant combine a double and datetime to form an array. So how can I do this for a app.UIaxes. For a normal plot it is easy, but here I need for app.UIaxes. How to do this. Thank you. matlab, appdesigner MATLAB Answers — New Questions