フィルターのクリア

Manipulating data from a table in app designer

7 ビュー (過去 30 日間)
sebastian marin quiceno
sebastian marin quiceno 2023 年 10 月 7 日
コメント済み: Voss 2023 年 10 月 8 日
Greetings everyone, my fundamental objective is to take the data from an app designer table and then use it. For example, add the data in position (1,1) with the data in position (1,2). But when I take them with the get(table, "Data") function and then use the str2double() function to supposedly convert the data type. When I use the disp() function in the command window I get "NaN".
When I write, for example, "2" and click Button. Spaces are formed in the table to write 2x5. That's where I type the numbers and then I want to try to access them through Button2.
function ButtonPushed(app, event)
global n;
global tabla;
n =1:5;
tabla = table;
for i = 1:app.EditField.Value
for j = n
tabla{i,j}=" ";
end
end
app.UITable.Data = tabla;
end
% Button pushed function: Button2
function Button2Pushed(app, event)
se = get(app.UITable,"Data");
si=str2double(se);
disp(si)
end

採用された回答

Voss
Voss 2023 年 10 月 8 日
tabla = table;
% ...
app.UITable.Data = tabla;
The uitable's Data is a table variable, so you need to get the data out of the table variable before doing str2double in Button2Pushed:
se = get(app.UITable,"Data");
si=str2double(se{:,:});
For example:
tabla = table("1","2") % a table variable
tabla = 1×2 table
Var1 Var2 ____ ____ "1" "2"
str2double(tabla) % NaN
ans = NaN
str2double(tabla{:,:}) % the contents of the table variable, [1 2]
ans = 1×2
1 2
  2 件のコメント
sebastian marin quiceno
sebastian marin quiceno 2023 年 10 月 8 日
Thanks a lot!
Voss
Voss 2023 年 10 月 8 日
You're welcome!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 10 月 8 日
Yes?
You are setting the fields to the blank string. str2double() of the blank string is NaN.
str2double(" ")
ans = NaN
  1 件のコメント
sebastian marin quiceno
sebastian marin quiceno 2023 年 10 月 8 日
It's true, you're right, I needed to detail the problem better. When I write, for example, "2" and click Button. Spaces are formed in the table to write 2x5. That's where I type the numbers and then I want to try to access them through Button2.

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by