Convert space separated string table to cell?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello :)
I can't seem to figure out how to convert a string table without using a (textscan etc.) loop,
from :
Table = ['A2 6C 33 04 00 81 00 80';'3F 11 65 01 0A '];
to :
Result = {'A2' '6C' '33' '04' '00' '81' '00' '80';'3F' '11' '65' '01' '0A' ' ' ' ' ' '};
Please note that "Table" is fixed-width Nx23 which could simplify things.
FYI, the end-goal is to convert from hex to decimal to cell-table:
Dec = [162 108 51 4 0 129 0 128; 63 17 101 1 10 0 0 0];
1 件のコメント
採用された回答
その他の回答 (3 件)
Azzi Abdelmalek
2014 年 6 月 17 日
Table = ['A2 6C 33 04 00 81 00 80';'3F 11 65 01 0A ']
Table(:,3:3:end)=[];
[n,m]=size(Table);
[bb,aa]=meshgrid(1:2:m,1:n);
out=arrayfun(@(x,y) hex2dec(Table(x,y:y+1)),aa,bb)
3 件のコメント
Azzi Abdelmalek
2014 年 6 月 17 日
Table = ['A2 6C 33 04 00 81 00 80';'3F 11 65 01 0A ']
Table(:,3:3:end)=[];
[n,m]=size(Table);
[bb,aa]=meshgrid(1:2:m,1:n);
out=arrayfun(@(x,y) Table(x,y:y+1),aa,bb,'un',0)
Andrei Bobrov
2014 年 6 月 17 日
編集済み: Andrei Bobrov
2014 年 6 月 17 日
nn = size(Table,1);
a = cellfun(@(x)regexp(x,'\w*','match'), num2cell(Table,2),'un',0);
n = cellfun(@numel,a);
mm = max(n);
m = mm - n;
b = arrayfun(@(x)[hex2dec(a{x});zeros(m(x),1)]', (1:nn)','un',0);
out = cat(1,b{:});
0 件のコメント
Azzi Abdelmalek
2014 年 6 月 17 日
編集済み: Azzi Abdelmalek
2014 年 6 月 17 日
Table = ['A2 6C 33 04 00 81 00 80';'3F 11 65 01 0A ']
[n,m]=size(Table)
Table(:,3:3:end)='/';
ss=regexp(num2cell(Table,2),'/+','split')
out=cellfun(@hex2dec,reshape([ss{:}],[],n)')
2 件のコメント
Cedric
2014 年 6 月 17 日
Careful, "faster" is not always "better"! My solution assumes that you know a priori the max width in terms of number of columns.
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!