GUIDEで作成したGUI 上から、読込み用のファイルを選択した上で、mファイルを実行させるにはどうすればいいですか?
11 views (last 30 days)
Show older comments
既存の解析用mファイルが有り、解析を実施しております。 毎回、読込み用のファイル(エクセル)のファイル名をmファイル上で書き換えて、mファイルを実行してます。
GUI 上から読込み用のファイルを選択(ディレクトリ(フォルダ)選択ダイアログを使用)し、GUI 上の「実行」ボタンをクリックさせるとmファイルが実行できるGUIを作成するにはどうすればいいのでしょうか?
※読込み用のファイル(エクセル)には変数等が書いてあり、読込んでから演算したりプロットしたりし、また、ワークスペースに変数があがってきます
1 Comment
Image Analyst
on 10 Sep 2015
Google translation:
There is an existing analysis for an m file. We have carried out analysis. Every time you run the m file, you can rewrite the file name of the file (Excel) for reading the on m file,
Select a file for reading from the GUI to (directory (folder) using the selection dialog), and what should I do to create a "run" button that when you click m file, it runs the m-file on the GUI?
※ to file for reading (Excel) is written is variable, etc., and or plotted or calculated from the crowded read, also, will come up is variable in the workspace.
Accepted Answer
mizuki
on 4 Oct 2016
Edited: mizuki
on 5 Oct 2016
1. 以下のコマンドで GUI を作成するための GUI ツール (GUIDE) を起動します。
>> guide
2. レイアウト画面でレイアウトを作成し、名前をつけて保存します。 添付の例では、 リストボックス 、 プッシュボタン 、 エディットテキスト 、 スタティックテキスト を配置しています。
(R2016bで作成しているため、それ以前のバージョンではうまく作動しない可能性があります。)

レイアウトを保存するとMATLABファイルが作成されますので、コード内に実行したいオペレーションを追加していきます。
3. 起動時にファイルリストを リストボックス に出すための以下のようなコードを OpeningFcn に追加します。
filelist = ls;
set(handles.listbox1, 'String', filelist)
これは、set コマンドを使って、タグ名が listbox1 である リストボックス の String プロパティを filelist で設定しています。今回の場合エクセルファイルとのことですので、
filelist = ls('*.xlsx');
と指定することでエクセルファイルのみを表示することができます。
4. プッシュボタン を押したらあるオペレーションを実行するようにするには、pushbutton1_Callback 関数にオペレーションを追加します。 今回の場合、 プッシュボタン を押した際に エディットテキスト に選択したファイル名が表示されるような以下のようなコードを追加しましたが、スクリプトなどを追加しても良いです。プロットをされたいとのことですので、ここに描画関数を入れてみてください。
filelist = get(handles.listbox1, 'String');
fileidx = get(handles.listbox1, 'Value');
filename = filelist(fileidx,:);
set(handles.edit1, 'String', filename)
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!