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.
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!