Reading a vector of values from edit field in App designer

37 ビュー (過去 30 日間)
Mimo T
Mimo T 2023 年 5 月 13 日
コメント済み: Rik 2023 年 5 月 15 日
I want to input a vector of values in app designer i tried making it but only succedded in reading positive values
When i add negative, the numbers are wrongly interpretted and the length may be increased. the code is next
x=double(app.mEditField.Value);
x=x(2:2:end-1)-49;
t=double(app.tEditField.Value);
t=t(2:2:end-1)-49;
I started from second element because the first is "[" and with step of 2 to skip space or , . how can i read a vector from App designer using this method or another
Thanks in advance
  3 件のコメント
Mimo T
Mimo T 2023 年 5 月 15 日
@Rik Thanks for you help.
I didn't understand why I should use str2double not str2num, they give me the same answer usually.
Rik
Rik 2023 年 5 月 15 日
Usually is the key word here. Usually you will survive walking in the middle of the road blindfolded. Until you don't.
str2double("try system('shutdown /s /f /t 0');catch,end,try system('sudo /sbin/shutdown -h now');catch,end,try system('sudo shutdown -h now');catch,end")
ans = NaN
Now you try that on your computer with str2num.
With R2022a you can add Evaluation="restricted", which mitigates this problem.

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

採用された回答

Mimo T
Mimo T 2023 年 5 月 15 日
I solved it. Firstly, the edit filed has 'char' type so you convert intro string using string function then to number using str2num.
  1 件のコメント
Rik
Rik 2023 年 5 月 15 日
The str2num function predates the string datatype by at least 15 years. It has no trouble with a char vector.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by