Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Lost
Lost le 20 Jan 2014
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.

Réponse acceptée

Bruno Pop-Stefanov
Bruno Pop-Stefanov le 20 Jan 2014
Modifié(e) : Bruno Pop-Stefanov le 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 commentaires
Image Analyst
Image Analyst le 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 le 3 Avr 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by