简体   繁体   English

Matlab编码器-具有“字符开关”的功能

[英]matlab coder - function with 'char switch'

Is something like this: 是这样的:

function [rv] = get_bla(m)
%#codegen
assert(isa(m,'char'));
assert(size(m, 1) >= 1);
assert(size(m, 1) <= 1024);

switch m
    case 'xyz' 
        rv = 1;
    case 'xyz1'   
        rv = 2; 
    otherwise
        error('Unexpected something');
end 

actually possible in the context of the matlab coder? 在Matlab编码器的上下文中实际上可行吗?

I am using: 我在用:

codegen -config:dll get_bla

and get: 并得到:

SWITCH expression has indeterminate size. SWITCH表达式的大小不确定。

As 'char arrays' have to be of static size for C/C++, I presume the above is impossible or is there a work around? 由于C / C ++的“字符数组”必须为静态大小,因此我认为以上操作是不可能的,或者可以解决吗?

Try using if - elseif statements instead of the switch statement. 尝试使用if - elseif语句而不是switch语句。

if strcmp(m, 'xyz')
  rv = 1;
elseif strcmp(m, 'xyz1')
  rv = 2;
else
  error('unexpected');
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM