how to save the data of an opened file by uigetfile in the workspace

5 ビュー (過去 30 日間)
imene. B
imene. B 2016 年 7 月 20 日
コメント済み: imene. B 2016 年 7 月 21 日
hello all,
i want to create a window that would be opened by a pushbutton, to open a file (a txt file) and then to load it to the workspace of matlab, i tried this code, it worked correctly but in the end i found nothing in the workspace, it doesn't save the data
filename = uigetfile('*.txt*', 'All Files (*.txt*)');
filename = uiimport(filename);
thank you.

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 7 月 21 日
imene - rather than re-using the same variable name for the data that is being imported, try
filename = uigetfile('*.txt*', 'All Files (*.txt*)');
data = uiimport(filename);
Now data is a struct that has the data that you have imported..which is in the workspace of your pushbutton callback. Depending upon how you have developed your GUI, you can either save this data to the handles structure (if using GUIDE) or you can save it to a local variable within your parent function that creates the GUI (assuming that you have nested your callback within that parent).
  8 件のコメント
imene. B
imene. B 2016 年 7 月 21 日
but how can i do that from within the GUI ? and as shown in the passed comment, i used assignin but it doesn't work too
imene. B
imene. B 2016 年 7 月 21 日
i solved it :)
filename = uigetfile('*.txt*', 'All Files (*.txt*)');
data = load(filename);
(assignin('base','data',data));
the tric is in 'load'
thank you Geoff for your help :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by