How do I pull data from a CSV into the GUI?
3 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Bruno Pop-Stefanov
2014 年 1 月 20 日
編集済み: Bruno Pop-Stefanov
2014 年 1 月 21 日
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 件のコメント
Image Analyst
2014 年 1 月 31 日
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
2016 年 4 月 3 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!