How do i read a line after a word in a csv file

조회 수: 8 (최근 30일)
Alex Perrakis
Alex Perrakis 2022년 8월 15일
댓글: Benjamin Thompson 2022년 8월 16일
Dear Matlab Community,
i have the following question,i have a .csv (attached) file which contains multiple data, before every data group there is a string, that defines what it is, for example "wavelength". The question is how do i search for a word in the .csv and then read the numbers after the word? Because of the format readtable does not exactly work :)
Thank you all in advance

채택된 답변

Benjamin Thompson
Benjamin Thompson 2022년 8월 15일
This could be a good example of using splitapply after reading in the entire dataset as a table. See this article:
https://www.mathworks.com/help/matlab/matlab_prog/split-table-data-variables-and-apply-functions.html?s_tid=srchtitle_Split%20Table%20Data%20Variables%20and%20Apply%20Functions_1
  댓글 수: 2
Alex Perrakis
Alex Perrakis 2022년 8월 16일
Readtable function does not work at all because of the format for some reason.
Benjamin Thompson
Benjamin Thompson 2022년 8월 16일
Your file is an odd format. How about this approach using textscan to parse it into a cell array and then strcmp to locate the word that you want in the array. I am not sure what you want to do with it from there.
fid = fopen('cycle3.csv', 'rt');
C = textscan(fid, '%s', 'Delimiter','\t');
I = strcmp(C{1}, 'MPECS Position (X Y Z)');
I2 = find(I);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by