Importing data from a text file in a standalone GUI windows application
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
Walter Roberson
am 26 Apr. 2012
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 Kommentare
Walter Roberson
am 26 Apr. 2012
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.
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!