Importing data from a text file in a standalone GUI windows application

3 ビュー (過去 30 日間)
Catherine
Catherine 2012 年 4 月 26 日
Hi there,
I've recently compiled my first standalone GUI. The program first shows an option window from which you select one of two options, and then depending on the option opens a second GUI. This second GUI imports data from text files stored in a sub-folder that I included in the 'additional files' using MCC when I built the thing.
This import works perfectly well when run from the command window, but fails miserably in the standalone. There's no error message, just a 'ding' that tells me something's gone wrong, and then it freezes. I'm using cd to change to the subfolder and importdata to import the text file. Can anyone help?
I've pasted a part of my code below...
First I set up all the buttons and stuff, which runs fine. The user is then prompted to input a string, and then press a button. On pressing the button, this executes:
S.R = get(S.ed(3),'String');
S.fileID=sprintf('000%s-ant_time_X.txt',S.R);
S.fileID2=sprintf('000%s-antstat.txt',S.R);
S.fileID3=sprintf('000%s-antangle.txt',S.R);
S.ID=sprintf('000%s',S.R);
s=str2double(sprintf('%s%s',S.R(1),S.R(2)));
end
cd data_for_gui
data=importdata(S.fileID);
datamat=(data.data);
T=datamat(:,1);
X=datamat(:,2);
Y=datamat(:,3);
This is the point at which I get 'ding'. A similar problem occurs in the other GUI which opens after the initial open window when the code requires importdata
Any advice much appreciated!

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 4 月 26 日
Is the file format known ahead of time? If it is, then when you are developing the code, use uiimport() and use its option to generate code that understands that file format, and incorporate that code instead of importdata().
You should also consider using textscan() instead of importdata()
  2 件のコメント
Catherine
Catherine 2012 年 4 月 26 日
Hi Walter, thanks for the suggestion - is textscan simply faster, or is importdata less compatible with standalone apps?
The file format is consistent, and runs fine in when I run the program from the command window, so I don't think the problem is there.
I just had a thought that perhaps the problem is using *cd* - is the current directory not the one with my second GUI? If not, that would explain why I'm unable to import anything! I was about to try recompiling it with the necessary textfiles in the same folder as the .m file.
Walter Roberson
Walter Roberson 2012 年 4 月 26 日
The current directory will seldom be the one you expect (unless you've had a lot of practice with the compiler.)
http://www.mathworks.com/support/solutions/en/data/1-6OFV37/
http://www.mathworks.com/help/toolbox/compiler/ctfroot.html
textscan() should in theory be faster.

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

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by