Clear Filters
Clear Filters

App designerで作​成したGUIのテーブ​ルデータをスクリプト​ファイルで取り出した​い

5 views (last 30 days)
Shumpei Hosokawa
Shumpei Hosokawa on 9 Nov 2023
Commented: Shumpei Hosokawa on 13 Nov 2023
表題の件につきまして質問があります.
App designerで値を入力するGUIを作成しています.以下に添付した画像がサンプルの画面となります.参考文献は以下の通りです.
ここで,Read excel datasを押すとX, Y, Zのコラムに値が読み込まれます.そしてRunボタンを押したらスクリプトファイル側でX, Y, Zのコラムのデータを読み込みたいです.
参考文献のコードを元に開発しています.また,Read excel dataボタン内のコードは以下の通りです.パブリックプロパティ内にテーブルデータの変数を宣言して,RunButtonPushedを押したときにスクリプトファイルに読み込めるように共有する方法がよいでしょうか?テーブルデータについては参考文献内に載っていなかったためやり方がよくわかっていません.
お手数おかけしますがよろしくお願いいたします.
properties (Access = public)
% Input Parameter GUI
sample1
% ここにTableデータの変数を宣言する?
end
% Code that executes after component creation
function startupFcn(app)
uiwait(app.UIFigure) % GUI を起動した時にプログラムを一時停止させる
end
% Button pushed function: Button
function ButtonPushed(app, event)
app.T = app.EditField.Value; % パラメータをパブリックプロパティに代入
uiresume(app.UIFigure) % コードの再開
end
function ReadexceldatasButtonPushed(app, event)
app.UITable.Data = readtable("my_parameters.xlsx");
end
% Code that executes after component creation
function startupFcn(app)
uiwait(app.UIFigure) % GUI を起動した時にプログラムを一時停止させる
end
% Button pushed function: RunButton
function RunButtonPushed(app, event)
% Edit parameters in GUI window
app.sample1Value= app.sample1.Value;
uiresume(app.UIFigure) % resume code
end

Accepted Answer

Kojiro Saito
Kojiro Saito on 13 Nov 2023
Edited: Kojiro Saito on 13 Nov 2023
テーブル型の場合も参考文献と同じようにパブリックプロパティとしてスクリプトに渡すことができます。
Runボタンを押したときのコールバックをパブリックプロパティ(sample1)を使うように変えてみてください。
% Button pushed function: RunButton
function RunButtonPushed(app, event)
% Edit parameters in GUI window
app.sample1 = app.UITable.Data; % テーブル型をパブリックプロパティに格納
uiresume(app.UIFigure) % resume code
end
呼び出し元のスクリプト
h = myapp; % GUI を出力引数付きで起動 (myapp.mlapp というファイル名の場合)
T = h.sample1; % パブリックプロパティの値を取得
close(h.UIFigure) % GUI を閉じる
disp(T)
  1 Comment
Shumpei Hosokawa
Shumpei Hosokawa on 13 Nov 2023
斎藤様
お世話になっております.
ご指摘の通りのコードに書き直してみましたところ正常に動作いたしました.ご教示ありがとうございました.

Sign in to comment.

More Answers (0)

Categories

Find more on GUIDE アプリの移行 in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!