Delete an array element using matlab function block in simulink
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Junyan Du
le 19 Fév 2020
i met this problem too, just cant figure it out why this doesnt wrok in Simulink block. lol
Réponses (1)
Rajanya
le 10 Fév 2025
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!
0 commentaires
Voir également
Catégories
En savoir plus sur Simulink Environment Customization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!