Hello I have the following problem: When I load data from a .dat file into matlab and create a table from it, matlab doesn't recognize the columns, so all the values ​​are in one column.
Arc 2, Z, Time: 0 00:00:000,260450,285
I would like the table separated as below
Time Distance WSPL
Arc 2, Z, Time: 0 00:00:00 0,260 450,285
Thank you very much for your help.

댓글 수: 3

Florian Rössing
Florian Rössing 2022년 5월 6일
Could you provide a minimal example matfile and your procedure as code snipets?
Frederik Reese
Frederik Reese 2022년 5월 6일
here the matfile
We need the original .dat file, not the .mat file.

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

 채택된 답변

Riccardo Scorretti
Riccardo Scorretti 2022년 5월 6일
편집: Riccardo Scorretti 2022년 5월 6일

1 개 추천

Perhaps you need something like this?
load Test_Table.mat
tab = table('Size', [numel(Test_Table) 3], ...
'VariableNames', {'Time', 'Distance', 'WSPL'}, ...
'VariableTypes', {'string', 'double', 'double'});
tm = {} ; dst = [] ; swpl = [];
for n = 1 : size(Test_Table,1)
buffer = char(Test_Table{n,1});
tab.Time(n) = string(buffer(1:27));
tm{n,1} = buffer(1:27);
t = str2num(strrep(buffer(28:end), ',', '.'));
tab.Distance(n) = t(1);
tab.WSPL(n) = t(2);
end
tab
tab = 21×3 table
Time Distance WSPL _____________________________ ________ ______ " Arc 2, Z, Time: 0 00:00:00" 0.26 450.29 " Arc 2, Z, Time: 0 00:00:00" 1.468 450.27 " Arc 2, Z, Time: 0 00:00:00" 2.798 450.27 " Arc 2, Z, Time: 0 00:00:00" 3.999 450.31 " Arc 2, Z, Time: 0 00:00:00" 5.202 450.32 " Arc 2, Z, Time: 0 00:00:00" 6.395 450.34 " Arc 2, Z, Time: 0 00:00:00" 7.591 450.34 " Arc 2, Z, Time: 0 00:00:00" 8.641 450.34 " Arc 2, Z, Time: 0 00:00:00" 9.835 450.35 " Arc 2, Z, Time: 0 00:00:00" 10.757 450.35 " Arc 2, Z, Time: 0 00:00:00" 11.942 450.33 " Arc 2, Z, Time: 0 00:00:00" 12.897 450.3 " Arc 2, Z, Time: 0 00:00:00" 15.207 450.52 " Arc 2, Z, Time: 0 00:00:00" 15.483 450.53 " Arc 2, Z, Time: 0 00:00:00" 15.707 450.53 " Arc 2, Z, Time: 0 00:00:00" 15.93 450.54
However, in my opinion, the point is rather how the original .dat file is imported.

댓글 수: 4

Florian Rössing
Florian Rössing 2022년 5월 6일
Yeah, the .dat file would be nice, it could be possible to read it as a csv, or write a custom parser for it, both not very hard. However this nice solution could be used to convert the wrongly read tables.
It is possible for sure. Let us see an example of .csv file.
Frederik Reese
Frederik Reese 2022년 5월 6일
yes it works. thanks a lot
have a nice weekend
My pleasure.

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

추가 답변 (1개)

Frederik Reese
Frederik Reese 2022년 5월 6일

0 개 추천

Here is the excel table. for this short List I can convert it in exel, but for the size I have I can't open it in excel. Is it possible to convert it, while loading it ?
Thanks

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by