Using pushbutton to load file in GUI

36 ビュー (過去 30 日間)
Jared
Jared 2011 年 11 月 1 日
I am new to creating a GUI. I am using guide, and have a push button that opens a uigetfile dialog box using the code:
[filename1,filepath1]=uigetfile({'*.*','All Files'},...
'Select Data File 1');
cd(filepath1);
rawdata1=load(filename1);
It seems to work. It opens, I select a file and hit ok, but there is no "rawdata1" in the matlab workspace. Where is this file stored?

採用された回答

Naz
Naz 2011 年 11 月 1 日
do this:
rawdata1=load([filepath1 filename1]);
GUI does not pass files to the workspace. You have to use the rawdata1 variable withing the function. You can make it semi-global by doing handles.rawdata1=load([filepath1 filename1]); and then access it the same way. If you leave the current function you must save changes to your handles.rawdata1 by typing this:
guidata(hObject, handles);
before you exit the function. If you want to copy the variable to the workspace, see my answer here: http://www.mathworks.com/matlabcentral/answers/19529-how-to-pass-arrays-to-and-from-a-gui
  1 件のコメント
Zhangxian
Zhangxian 2013 年 11 月 19 日
Great! It helps a lot

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

その他の回答 (3 件)

Ka Mirul
Ka Mirul 2017 年 11 月 20 日
I found a video that help me, it is about creating GUI to browse an image and display the image and its name. It should help you : https://youtu.be/7EmFShs5y9I
  2 件のコメント
nissrine Neyy
nissrine Neyy 2021 年 1 月 4 日
Thank you, it was helpful.
here's the code if anyone needed it :
[filename, filepath] = uigetfile({'*.*';'*.jpg';'*.png';'*.bmp'},'Search image to be displayed');
fullname = [filepath filename];
ImageFile = imread(fullname);
axes(handles.axes1)
imagesc(ImageFile)
Amirullah Bin Abdul Razak
Amirullah Bin Abdul Razak 2022 年 9 月 27 日
Hi ,
Can assist in providing the codes to upload video files using gui pushbutton? handles.axes1
Thank you.

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


Fangjun Jiang
Fangjun Jiang 2011 年 11 月 1 日
編集済み: John Kelly 2015 年 2 月 26 日
Your code is inside a GUI callback function so rawdata1 is in the function workspace, not the MATLAB base workspace.
To load into the base workspace, you need to use evalin() or assignin()

Micah
Micah 2011 年 11 月 1 日
GUIs (and functions) do not put variables into the 'seen' matlab workspace. They are in a separate space for that specific GUI (or function). So loading a variable in a GUI will not allow you to manipulate it in the workspace, and loading a variable in the workspace will not allow the GUI to use it. Also, if you have two GUIs, and load the variable 'rawdata' in the first, the second will not be able to use it, and you won't ever be able to 'see' it in the workspace.

カテゴリ

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