Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Read in CSV files using GUI

Asked by T on 13 Jan 2013

If I want MATLAB to read in the following file using the GUIDE feature in MATLAB:

Source File:

ID:
C
C
C
C
R
F
L
T
E
Date Time Ch:
03/24/2012 28:43.0 -142.315
03/24/2012 28:43.0 -142.316
03/24/2012 28:43.0 -142.318

and so on,

how can I read the file if the extension is not .csv, say, .pl4?

With a .csv I could use the following but that only assumes if the file .csv which in my case it's not.

fid=fopen('filename.csv');
header = textscan(filenamecsv, '%s',3, 'delimeter' ',','headerLines',16);
data=textscan(filenamecsv, '%s %s %s', 'delimiter', ' ,');
data_to_plot=str2double(data{3});
fclose(filenamecsv);

0 Comments

T

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson on 13 Jan 2013
Accepted answer
fid = fopen('filename.pl4');
header = textscan(fid, '%s', 3, 'headerLines', 16);
data = textscan(fid, '%s %s %f');
data_to_plot = data{3};
fclose(fid);

0 Comments

Walter Roberson
Answer by T on 13 Jan 2013

But if I create a function:

function openfile_Callback(hObject, eventdata, handles)

[filename,pathname,filterIndex] = ... uigetfile({'*.p4';),['Select the file'],... );

do I still need fid = fopen ?

14 Comments

Walter Roberson on 17 Jan 2013

You cannot effectively use a waitbar in that situation, as you have no information about how long the load will take, and you are only doing a single operation (that is, a single textscan()).

T on 17 Jan 2013

suppose it takes 30 seconds? There is the for loop in the documentation for waitbar but it iterates then executes the commands I have after, delaying the processing rather than assessing it.

Walter Roberson on 17 Jan 2013

If you know how long it will take, use a timer object to update it, and hope that the innards of textscan() are not built-in functions (timers cannot interrupt built-in functions.)

T

Contact us