How to get input vector from a user in App Designer?

Hi,
I am using App Designer to build a GUI interface for my code. My code requires a numeric input from user to start. I used the Numeric Box available in App Designer but it did not work all types of number. So, I want the App to accept the user input of any type either integer, decimal or vector.
One example, the user can input A = 1 Another example, the user can input A= 0.5 or even a vector, A= 1 2 3 0.5 0.7 ..etc
I hope you can help me on this?
Thanks

 Accepted Answer

To input a vector and decimals, I suggest you to use Numeric Text Field because by the help of conversions, you are able to get input vector. What you write to those fields are obtained as strings by default, so all you need to do is to convert them to double, but input the vectors by writing commas like:
a=app.NumericTextEditField.Value;%your input is a=[1,2,3,4];
aConverted=str2double(strsplit(a,','));
By this conversion, you obtain a numeric vector. Hope this helps and you understand what I mean.

6 Comments

yep, it is perfect! it works now. Thanks
Hello
I have the same task, but I want to summarize this number. Whan I use Numeric Text Field it doesn't work,so I use Text Field
I can't get right answer
my code is :
function ButtonPushed(app, event)
a=app.EditField2.Value;
aConverted=str2double(strsplit(a,','));
a1=sum(aConverted)
app.Label.Text=num2str(aConverted)
app.Label2.Text=num2str(a1)
end
my input is a=[1,2,3,4]; in Text Field
and resuls:
in Label: Nan 2,3,Nan
in Label2: Nan
Can you help me please;
Thanks
I have solved this problem myself programically
function ButtonPushed(app, event)
a=app.EditField_2.Value;
ac=[]
b=erase(a,{'[',']'})
a=split(b,{' ',','})
i=1;
while i<=length(a)
ac=[ac,str2double(a(i))]
i=i+1;
end
app.Label.Text=num2str(sum(ac))
end
if my input is : [1 2 3 4] answer in Label will be 10, so it works!
I just wanted do easyer than here
I appreciate it, thanks for the answer Irma
thanks, but, how can i use this with negative numbers input?

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!