作者ice77 (ice)
看板MATLAB
标题[讨论] Cell相邻数值合并
时间Wed Oct 19 07:22:49 2016
各位大大好...
小弟处理资料时
有一个56*1的Cell
每个Cell里的长度可能不一
例如A=[68 83 67]
B=[68 84 47 78 66 31995 32113]
小弟想将每一列"相邻"的数值合起来
变成像是A=[688367]
B=[68844778663199532113]
这样的型态
已爬过文章
用过像是cat horzcat等但仍无法解决
想利用cellfun又因A B的长度不一样无法使用
想请求各位大大的帮助
谢谢大家!!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.193.237.117
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1476832972.A.EAB.html
1F:→ ice77: 谢谢各位,已经找出方法了! 10/19 16:28
2F:→ ice77: 先用num2str,将这些数值转换成char格式 10/19 16:30
3F:→ ice77: 再用strrep,此时相邻的数字已可以合起来了 10/19 16:31
4F:→ ice77: 最後再用cellstr,还有cellfun,此时数字已全为double格式! 10/19 16:32
附上程式码
for i=1:length(C)
C_test{i,4}=num2str(C_test{i,3});
end
C_test2=C_test(1:end,4);
C_test2=strrep(C_test2, ' ', '');
C_test3=cellstr(C_test2);
C_test3=cellfun(@str2num,C_test3);
※ 编辑: ice77 (123.193.237.117), 10/19/2016 16:32:36