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

5 ビュー (過去 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 ].
  1 件のコメント
Palma Errico
Palma Errico 2021 年 2 月 19 日
how do you build a vector and what component should you take from the library?

サインインしてコメントする。

採用された回答

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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by