How to make an Edit Text Field box in App Designer to recognize a vector input

조회 수: 11 (최근 30일)
I am using an Edit Field Text box for a user to input a numerical vector array. For example, I want the inputs to follow regular vector array notation 4:5 or 1:5:10 or just one number. I have found another users post where this question was partly answered. I was able to get it to recognize the inputs as a vector. But for an input such as 1:4 it would only see the numbers 1 and 4 [ 1 4 ] when it should have a vector so that it counts 1 through 4 [ 1 2 3 4 ].

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 6월 4일
The text field are designed to take in string inputs. It will return you whatever data is entered as string.
If you want to interpret this string, you have to write a function that parses the string in the manner you want it to be parsed. It is not recommended to use eval function with user inputs, as the user can then key in anything causing your program to break.
You have to decide what are the acceptable patterns of input and then write a parser that extracts these patterns for you.
In this case one of the input pattern you have is %i:%i. You can use regexp to extract these and other patterns.
stringvalue = '12:24';
out = regexp(stringvalue,'(?<d1>\d+):(?<d2>\d+)','names');
arr = str2double(out.d1):str2double(out.d2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by