フィルターのクリア

display numeric row vector in app designer text box

5 ビュー (過去 30 日間)
Alex Mason
Alex Mason 2023 年 8 月 21 日
編集済み: Alex Mason 2023 年 8 月 21 日
I'm sure this is straight forward but I can't quite get it to work right.
I've got some code that will produce a row vector. The vector could be = [1,2,3,4,5] or it could = [1,5,6,9] or anything in between. Its just a list of unique values from some previous step.
But I want it to appear in a text box, on the app UI, like [n1,n2,n3...nx]. It doesn't have to show the brackets, but the numbers separated by comma would be ideal.
I've tried:
app.EditField.Value = evalc('Variable');
And that literally puts "Variable = 1 2 3 4 5"
I also tried:
app.EditField.Value = convertCharsToStrings(num2str(Variable));
Which, to me looks clunky (convert to string, then convert to char) and then it only puts out 1 2 3 4 5
Is there a clean way to get -> 1,2,3,4,5 in the text box?

採用された回答

Cris LaPierre
Cris LaPierre 2023 年 8 月 21 日
The comma is a separator for building the vector, but is not actually part of the vector. Therefore, you will have to add it manually.
Off hand, I can't think of a 'one-line' way to do that. I'd probably do something like this.
a=1:5;
vec = sprintf('%g,',a)
vec = '1,2,3,4,5,'
app.EditField.Value = vec(1:end-1);
% visualize the result
app.EditField.Value
ans = '1,2,3,4,5'
  2 件のコメント
Cris LaPierre
Cris LaPierre 2023 年 8 月 21 日
Update - here's a simple one-line approach
a=1:5;
strjoin(string(a),",")
ans = "1,2,3,4,5"
Alex Mason
Alex Mason 2023 年 8 月 21 日
編集済み: Alex Mason 2023 年 8 月 21 日
Awesome, this works, Thanks!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by