Readtable from a text file with multiple delimiter

Hello,
I have a text file with column delimited by tab , but the string containing the variable name has as a delimiter simple multiple space.
Is there a way to specify that the delimiter of the variable name row is different from the rest of the file ?

댓글 수: 1

Rik
Rik 2020년 11월 2일
I don't have the actual answer, but you could parse them separately.

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

 채택된 답변

Rishik Ramena
Rishik Ramena 2020년 11월 6일
You can try using readcell in the following way. I'm not sure how your data looks like. If this does not help in your data, you can try importing the data interactively using the Import Tool.
table = readcell('rows.txt', 'Delimiter', ' ')
% 2×5 cell array
%
% {'peter'} {'pan'} {[10]} {[ 2]} {[30]}
% {'john' } {'doe'} {[30]} {[50]} {[60]}
col_1 = table(:, 1);
col_2 = table(:, 2);
name = strcat(col_1, {' '}, col_2)
% name =
%
% 2×1 cell array
%
% {'peter pan'}
% {'john doe' }

댓글 수: 4

Thank you, it helped. Do you know if there is a function that returns the number of the lines where there is an occurrence of a given expression? I mean I want to find on which lines the word "hello" is found in a text
Rik
Rik 2020년 11월 6일
Are you interested in the line number in your file, or in your variable?
In the file.
Rik
Rik 2020년 11월 7일
You can get my readfile function from the FEX. If you are using R2017a or later, you can also get it through the AddOn-manager. That will read your file to a cell array (1 cell per line), after which you can loop through the lines and use something like contains.

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

추가 답변 (0개)

카테고리

질문:

2020년 11월 2일

댓글:

Rik
2020년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by