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

5 visualizaciones (últimos 30 días)
Lost
Lost el 20 de En. de 2014
Comentada: kayal gurunath el 3 de Abr. de 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.

Respuesta aceptada

Bruno Pop-Stefanov
Bruno Pop-Stefanov el 20 de En. de 2014
Editada: Bruno Pop-Stefanov el 21 de En. de 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 comentarios
Image Analyst
Image Analyst el 31 de En. de 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 el 3 de Abr. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by