How can I use simulink to merge four elements in a matrix to become just one symbol?

1 次查看(过去 30 天)
I have tried using the embedded matlab function, but ended up gettin the error "Subscripting into an mxArray is not supported"
For example, assuming I'm receiving a 12x1 matrix element from a simulink block [1;2;3;4;5;6;7;8], I want simulink to group the first 4 elements and merge or symbolise it as 1234(i.e a single integer), and carry on like that for the next 4 elements. I.e, 5678 for the next set.
Here is what I vae put inside the embedded function: %---------------------------------------------------------- function y = fcn(u) formatSpec = '%d%d%d%d' A=0;A=length(u); y = (zeros(length(u),4,'double'));%y=yy; coder.extrinsic('sprintf','str2double'); u=str2double(u);
for n=1:4:A y=sprintf(formatSpec,u(n), u(n+1), u(n+2), u(n+3)); %y=[y yy]; end %------------------------------------------------------------
Anyone with the idea should please bail me out. Regards, Ken

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by