Filter löschen
Filter löschen

How do I pull data from a CSV into the GUI?

2 Ansichten (letzte 30 Tage)
Lost
Lost am 20 Jan. 2014
Kommentiert: kayal gurunath am 3 Apr. 2016
I have a csv with a bunch of variables.
I want matlab to open the CSV, and put the first variable into one field, the second variable into the next field, etc.
How can I do this?
My csv file is actually a text file, test_file.txt Which contains: 1,120,5e-05,000035,5,1000000,2425,102e-05,1,2,3,4,1e-15,15,0,32
So I want Matlab to put 1, 120, etc into the various fields I have in the GUI.
Thank you for your help and time.

Akzeptierte Antwort

Bruno Pop-Stefanov
Bruno Pop-Stefanov am 20 Jan. 2014
Bearbeitet: Bruno Pop-Stefanov am 21 Jan. 2014
The following code should work:
% Open CSV file
fid = fopen('myCSV.txt', 'r');
% Read comma-separated values
A = fscanf(fid, '%f,');
% Don't forget to close the file
fclose(fid);
All your values will be stored in the vector A. You can then access them by calling A(1), A(2), A(3), etc...
Note that values have to be written in the text file like you said ("value1,value2,value3"); otherwise, it won't read them correctly. Let me know if you have more questions.
  3 Kommentare
Image Analyst
Image Analyst am 31 Jan. 2014
Yes, put it in the callback for the submit button, if that is where you thing the best place to read in the file is. If you have a uitable and want to display the data in the grid/table control, then pass Bruno's "A" into set():
set(handles.uitable1, 'Data', A);
kayal gurunath
kayal gurunath am 3 Apr. 2016
HI, I am reading a csv file and writing it to uitable on a button click. the data is getting overwritten on the same grid column for every line of csv file..how to get rid of the problem? am using the above mentioned code within the file reading loop

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by