Convert a string cell value to representative datas

test{1,1}=['0,+,ESI,ms1,-,line,1.1-790.4,275,1.1 41,1.2 30,1.6 10,1.7 24']
test{2,1}=['0.0505163,+,ESI,ms1,-,line,1.1-834.0,254,1.1 26,1.2 16,1.3 52,1.4 30,1.5 12']
test{3,1}=['0.103382,+,ESI,ms1,-,line,1.1-895.4,252,1.1 12,1.4 21,1.5 40,1.6 29,1.7 10']
i want to convert to a struct that the value in the first comma respresents one axis(retention time), the second to sixth comma represents the analisys parameters. The ninth comma and on represents the values of the X, Y data. How i can do that Best Regards Rafael

8 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 7 月 11 日
How did you get "test" in the first place?
Rafael Freire
Rafael Freire 2011 年 7 月 11 日
Its was exported as ACSII from a Mass spectometer
Oleg Komarov
Oleg Komarov 2011 年 7 月 11 日
Then, it would be much straightforward to import it with textscan and then do the manipulations.
Rafael Freire
Rafael Freire 2011 年 7 月 11 日
How i do that?
Oleg Komarov
Oleg Komarov 2011 年 7 月 11 日
Post the first 3 lines of your ascii file and tell me which columns you really need.
Rafael Freire
Rafael Freire 2011 年 7 月 11 日
0,+,ESI,ms1,-,line,1.1-790.4,275,1.1 41,1.2 30,1.6 10,1.7 24,1.9 30,1.9 20,2.0 18,2.0 41
0.0505163,+,ESI,ms1,-,line,1.1-834.0,254,1.1 26,1.1 16,1.2 52,1.3 30,1.4 12,1.8 23,2.0 17,2.1 12,2.4 11
0.103382,+,ESI,ms1,-,line,1.1-895.4,252,1.1 12,1.4 21,1.5 40,1.6 29,1.7 10,1.7 28,2.0 19,2.1 11,2.1 16,2.1 21,2.2 22,2.2 14,2.4 10,2.7 13,2.8 10,3.5 21,3.6 12,3.6 11,3.7 23,3.7 18,4.2 20,4.7 14,4.9 12,4.9 11
for the first line i need the parameters
0
+
ESI
ms1
-
line
1.1
-790.4
275
than is the values for X,Y
1.1 41
1.2 30
1.6 10
1.7 24
1.9 30
1.9 20
2.0 18
2.0 41
Oleg Komarov
Oleg Komarov 2011 年 7 月 12 日
Are the fields 2-6 always 1,3,3,1,4 characters?
Also,after line you always have a float followed with by a negative float with no space in between?
Rafael Freire
Rafael Freire 2011 年 7 月 12 日
Yes and Yes

サインインしてコメントする。

 採用された回答

Oleg Komarov
Oleg Komarov 2011 年 7 月 12 日

0 投票

Con sidering that I created a temp.txt containing:
0,+,ESI,ms1,-,line,1.1-790.4,275,1.1 41,1.2 30,1.6 10,1.7 24,1.9 30,1.9 20,2.0 18,2.0 41
0.0505163,+,ESI,ms1,-,line,1.1-834.0,254,1.1 26,1.1 16,1.2 52,1.3 30,1.4 12,1.8 23,2.0 17,2.1 12,2.4 11
0.103382,+,ESI,ms1,-,line,1.1-895.4,252,1.1 12,1.4 21,1.5 40,1.6 29,1.7 10,1.7 28,2.0 19,2.1 11,2.1 16,2.1 21,2.2 22,2.2 14,2.4 10,2.7 13,2.8 10,3.5 21,3.6 12,3.6 11,3.7 23,3.7 18,4.2 20,4.7 14,4.9 12,4.9 11
Edit
% To import:
fid = fopen('temp.txt');
fmt = '%f,%1s,%3s,%3s,%1s,%4s,%f%f,%f,%s';
% Tweak 4095*n to augment the buffer
opt = {'Delimiter','','CollectOutput',1,'BufSize',4095*3};
out = textscan(fid,fmt,opt{:});
out{end} = cellfun(@(x) textscan(x,'%f %f','Delimiter',',','CollectOutput',1),out{1,end});
fclose(fid);
Now every bit of data is in the right format but it's not stored in the best way.

7 件のコメント

Rafael Freire
Rafael Freire 2011 年 7 月 12 日
When i run the second command line it give me an error:
??? Error using ==> textscan
Buffer overflow (bufsize = 4095)
while reading string from
file (row 11, field 18). Use
'bufsize' option. See HELP TEXTSCAN.
Oleg Komarov
Oleg Komarov 2011 年 7 月 12 日
It seems to have a problem with line 11. Can you post it (should be out{1,end}{11})?
Rafael Freire
Rafael Freire 2011 年 7 月 12 日
the problem is that the first lines has 2141 characters and the line 11 has 10777 characters
Rafael Freire
Rafael Freire 2011 年 7 月 12 日
Oleg, you did all right only forget the value of bufsize
fid = fopen('teste2.ascii')
out = textscan(fid,'%f,%1s,%3s,%3s,%1s,%4s,%f%f,%f,%s','Delimiter','','CollectOutput',1,'bufsize',250000)
out{end} = cellfun(@(x) textscan(x,'%f %f','Delimiter',',','CollectOutput',1),out{1,end})
fclose(fid)
Thank you veru much!!!!
Rafael
Oleg Komarov
Oleg Komarov 2011 年 7 月 12 日
You can delete your comment, it's too long :).
See my edit above.
Oleg Komarov
Oleg Komarov 2011 年 7 月 12 日
Didn't see your answer because I didn't refresh. I knew about buffer size but was working also on an alternative in case your each the limit. Let me know if it works consistenlty, otherwise you can setup a loop with low level import with fscanf.
Cheers
Rafael Freire
Rafael Freire 2011 年 7 月 12 日
Great! Thank You!
Best regards!
Rafael

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by