필터 지우기
필터 지우기

Importing data into datastructure with GUI

조회 수: 8 (최근 30일)
Adam
Adam 2011년 8월 9일
I have a large dataset in .txt format which i want to load from a GUI into a data structure. I have managed to make a browse window when i push a button, where i can select the file, with this code:
function browse_Callback(hObject, eventdata, handles) %generated by GUIDE
A=ImportData()
I have made this function to import the data indto a data structure:
function A = ImportData() %ImportData function
FileName = uigetfile('*.txt','Select the MATLAB code file')
A = importdata(FileName) %import data from file, into structure A
end
But it seems like it doesnt save the data into the data structure (cant see it in workspace), which is a problem because i want to do some calculations with the data. What am i doing wrong?
I am pretty new with GUI, and still learning! Hope someone will be able to help.
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 8월 9일
The above code will fail if the user selects a file that is not in the current directory, as you do not record the directory name information that uigetfile() is willing to return.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 9일
The variable A is in your function workspace, not the base workspace.
  1. You can put a break point in your code to debug it. When you debugging, you can go to the Command Window to observe the variable in your function workspace.
  2. You can use assignin('base','A',importdata(FileName)) to assign the variable in base workspace.
  3. Probably there is no need to create your own "ImportData" function. It's so close to the built-in importdata() function. Why not put the uigetfile() line and importdata() line in your browse_Callback() function.
  댓글 수: 1
Adam
Adam 2011년 8월 9일
thx :)
2. was working... 3. did not!
But i am not sure what you mean by base workspace?
when i make a normal script i have no problems using functions and variables created inside the function?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by