text to column conversion

8 ビュー (過去 30 日間)
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 6 月 2 日
コメント済み: Roger Wohlwend 2014 年 6 月 3 日
Hi, I have a cell array and I'm seeking to separate two words and save them in 2 columns.
say the original cell array is tags and the modified array should look as follow
tags={'C=10.0mF L=1.0mH', 'C=10.0mF L=10.0mH' ,'C=50.0mF L=6.0mH'}
% I would like to have a script to bulil tags_new in the following format
tags_new={'C=10.0mF' 'L=1.0mH' ; 'C=10.0mF' 'L=10.0mH' ;'C=50.0mF' 'L=6.0mH'}
The idea is to detect the space delimiter before "L=" and move it to a different column.
This is achievable excel using "text to columns function"

採用された回答

Roger Wohlwend
Roger Wohlwend 2014 年 6 月 2 日
n = length(tags);
tags_new = cell(n,2);
for k = 1 : n
tags_new(k,:) = strsplit(tags{k},' ');
end
  2 件のコメント
Rashmil Dahanayake
Rashmil Dahanayake 2014 年 6 月 2 日
thanks, but Matlab 2012a doesn't have the strsplit().
Roger Wohlwend
Roger Wohlwend 2014 年 6 月 3 日
n = length(tags);
tags_new = cell(n,2);
for k = 1 : n
z = find(tags{k} == ' ');
tags_new{k,1} = tags{k}(1:z-1);
tags_new{k,2} = tags{k}(z+1:end);
end

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by