plot two arrays as y and x axis in matlab app designer

1 次查看(过去 30 天)
I wanted to plot load given in the array as [0 0 1 1] (i have used text field as text)in y direction which changes with respect to time as given as [0 25 60 100](i have used text field as text)in matlab app designer.(so here in the y direction the load is 0 from 0 to 25 sec then from 25 sec to 60 sec load increases from 0 to 1 after that load remains constant as 1 for the remaining time as shown in the figure attached ).can u please provide me the code to plot these two arrays (load and time) in matlab app designer.plzz help me out.i have attached the plot that i need in the app designer.

采纳的回答

dpb
dpb 2023-7-15
编辑:dpb 2023-7-17
Show us what you've tried...this is trivial from the links I've shown you before.
The only issue is you will have to convert the text fields to numeric arrays, but this is also pretty-much dead-ahead string interpretation...the hardest part will be ensuring the user enters valid text and there are same length vectors, etc., etc., etc, ... You might want to reconsider how the user is to specify the number and values of the points to make certain the input returned is valid instead of trying to parse what could be free form input...
But, given your example...
load=str2num(app.yText.Value);
t=str2num(app.xText.Value);
plot(t,load)
is the bare bones of it -- of course, as noted, the above will need to be in a |try...catch..end] block with a lot of error checking to be able to be sure you have actual data; the free form user input is going to be a lot of trouble.
You would do the user a big favor in providing more context -- just an "X" and a "Y" is pretty hard to tell about although maybe there is sufficient surrounding other information it makes more sense than just standing alone. But, I would suggest using meaningful labels including telling the user what units of time and load are expected -- unless those are being set somewhere else, too, of course.
  2 个评论
Ayush Varun
Ayush Varun 2023-7-16
Thank you for the reply... I think I can solve the issue now..
Regards
dpb
dpb 2023-7-16
You could at least set the property of the edit field to numeric although I don't know if it will then accept more than one number in one field; you might have to enter each individually, also a pain that way.
A more suitable form for such might be to use a user-editable uitable that you could start with some number of available rows such as 5 or so as you've got here. Then you can control the content of each cell to constrain to be numeric as well as have a convenient table in the code for the content...I think you've not yet thought of all the issues you're going to have to cope with if you just let the user type randomly into a text box here...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by