Delete an array element using matlab function block in simulink

조회 수: 3 (최근 30일)
lorenzo angeloni
lorenzo angeloni 2018년 5월 19일
답변: Rajanya 2025년 2월 10일
Hi i tried to build this simple code, to delete an element from an array 'u' in input using a matlab function block. This is the code of the function block:
-function y = fcn(u);
-u(u==2) = [];
-y = u;
I can not understand why i obtain this error : Dimension 1 is fixed on the left-hand side but varies on the right ([3 x 1] ~= [:? x 1]). I tried to set the variable size from 'Edit data' in the function editor but doesn't work. Someone can help me please?
  댓글 수: 2
Junyan Du
Junyan Du 2020년 2월 19일
i met this problem too, just cant figure it out why this doesnt wrok in Simulink block. lol
Pawan Pawar
Pawan Pawar 2020년 6월 15일
Hey, Did you got any break throgh. I am also stuck here

댓글을 달려면 로그인하십시오.

답변 (1개)

Rajanya
Rajanya 2025년 2월 10일
The reason for this error is that the code in the MATLAB Function Block is trying to change the size of the input itself. 'Variable size' property applies only to variables with 'Scope' property set to 'Output' - Define MATLAB Function Block Variables.
Modifying the code like the following resolves the error since it creates a copy of the input first and then removes one element from there-
function y = fcn(u)
y=u;
y(u==2)=[]; %delete the element from 'y' and not 'u'
Also, the output variable 'y' should be set to 'variable size' and the size can be specified to be 'size(u)' to prevent the output signal from getting unbounded (otherwise, the display block would not be able to display the output).
Hope this would help. Cheers!

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by