Going from a string to a matrix

I want to use information from a .dat document, which is the outcome of some experiments. I used the following code to put the information in an array:
fid = fopen('glhedata.dat'); n = 1; textline = {}; while( ~feof(fid) ) textline(n,1) = {fgetl(fid)}; n = n + 1; end fclose(fid);
For example, on row 36 I got a string: ('january 00.0000 5.22222 6.32555 2.5548'). I want to put this string in a matrix (or vector) like this: A = ('january'; 00.000 ; 5.22222; 6.325555; 2.5548;), so that i can use the numerical values and january stays a string. I tried to use sscanf, but that doesnt seem to work. Can anybody help me?
Nick

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 27 日

0 投票

s='january 00.0000 5.22222 6.32555 2.5548'
out=regexp(s,'\s+','split')

この質問は閉じられています。

質問済み:

2013 年 11 月 27 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by