[英]Matlab Coder - Alternative for strcat function
Currently matlab coder is not supporting strcat
or strjoin
. 目前matlab编码器不支持
strcat
或strjoin
。 Is there any anyway to circumvent this or custom function? 有没有办法绕过这个或自定义功能?
Edit: Input= [abcd] Expected output= 'a,b,c,d' 编辑:输入= [abcd]预期输出='a,b,c,d'
For strjoin
you might get away with sprintf
: 对于
strjoin
你可以逃脱sprintf
:
>> colorCell = [{'Red','Yellow'},{'Green','Blue'}];
>> colorList = strjoin(colorCell,',')
colorList =
Red,Yellow,Green,Blue
>> colorList = sprintf('%s,',colorCell{:}); colorList(end)=[]
colorList =
Red,Yellow,Green,Blue
If you can't use spintf
: 如果你不能使用
spintf
:
>> c = [colorCell(:) repmat({','},numel(colorCell),1)].';
>> colorList = [c{:}]; colorList(end)=[]
For strcat
, simple usage is often equivalent to using []
. 对于
strcat
,简单的用法通常等同于使用[]
。
>> strcat(colorCell{:})
ans =
RedYellowGreenBlue
>> [colorCell{:}]
ans =
RedYellowGreenBlue
However, for more complex syntax, it's not that simple: 但是,对于更复杂的语法,它并不那么简单:
>> strcat({'Red','Yellow'},{'Green','Blue'})
ans =
'RedGreen' 'YellowBlue'
Do you need a solution for this usage? 您是否需要针对此用途的解决方案? Perhaps the following:
也许如下:
colorCell1 = {'Red','Yellow'}; colorCell2 = {'Green','Blue'};
colorCell12 = [colorCell1;colorCell2];
c = mat2cell(colorCell12,size(colorCell12,1),ones(size(colorCell12,2),1));
cellfun(@(x)[x{:}],c,'uni',0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.