How to make an Edit Text Field box in App Designer to recognize a vector input
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Forrest Ward
le 3 Juin 2020
Commenté : Palma Errico
le 19 Fév 2021
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 commentaire
Palma Errico
le 19 Fév 2021
how do you build a vector and what component should you take from the library?
Réponse acceptée
Mohammad Sami
le 4 Juin 2020
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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!