String with csv in matlab

2 ビュー (過去 30 日間)
Fredrik
Fredrik 2011 年 10 月 24 日
Hi I have a string in matlab A = "2011-08-18,00:10:00,600,6.2,5.4, " etc... Can i make this Csv-string into data? (I have a lot of these from an earlier bad import)
Thank you! Fredrik
  2 件のコメント
Jan
Jan 2011 年 10 月 24 日
It depends on what "data" means exactly. Please explain the type of the input (string, cell string, test file, MAT file?) and the wanted output explicitely.
Fredrik
Fredrik 2011 年 10 月 24 日
First of all, i have a cell array called Text with a lot of strings, that look like the one above. Text{1} and Text{2} is
'2011-08-18,00:10:00,600,1.56188,3.33684,4.328568,2.03864' and
'2011-08-18,00:20:00,600,7.26988,7.23684,0.328568,8.03864'
What I would like to do is eventually to get the values from these strings into a matrice with NewText(1)= '2011-08-18, 00:10:00'
and Data (1,1)= 600 for example.
So first my thought was to export this out from matlab in some way and then import it back with csvread for example, but would be more efficient to do it all inside matlab!

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

採用された回答

TAB
TAB 2011 年 10 月 24 日
Text={'2011-08-18,00:10:00,600,1.56188,3.33684,4.328568,2.03864';'2011-08-18,00:20:00,600,7.26988,7.23684,0.328568,8.03864'};
TextLen=length(Text);
NewText=cell(TextLen,2);
Data=zeros(TextLen,5);
for x=1:length(Text)
SplitData=textscan(Text{x},'%s','delimiter',',');
NewText{x}={SplitData{1}{1},SplitData{1}{2}};
Data=(str2double({SplitData{1}{3:end}}));
end
  1 件のコメント
Fredrik
Fredrik 2011 年 10 月 24 日
Perfect, thanx alot for your time and a great answer!

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

その他の回答 (1 件)

Fredrik
Fredrik 2011 年 10 月 25 日
Do you have any idea on how to increase the speed of this? This way of importing takes about 1 second per file I import, and since it is about 50 of them, it would be nice for some more speed :) For example, is it possible to use the textscan without going through a for loop, more like a vector operation?
  1 件のコメント
TAB
TAB 2011 年 10 月 27 日
Try *cellfun*
See doc cellfun

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

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by