![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1814018/image.png)
Matlab function in simulink
1 view (last 30 days)
Show older comments
Errors occurred during parsing of MATLAB function 'MATLAB Function'(#35)
Error in port widths or dimensions. Output port 1 of 'rectinput/MATLAB Function/d' is a one dimensional vector with 1 elements.
my coding is
function y = fcn(a,b,c,d)
%#codegen
v = rectangle('Position',[a b c d]);
axis ([0 10 0 10]);
y = v;
0 Comments
Answers (1)
Pramil
on 26 Nov 2024
Hey Vimala,
The error you're encountering is related to the output dimensions of the "MATLAB function" block.
In your code, you're trying to assign the output "y" to the result of the "rectangle" function, which doesn't return a numeric value but rather a handle to the rectangle object. This is likely causing the mismatch in expected output dimensions.
If your goal is to visualize a rectangle and not return any specific numeric output, you might want to adjust your function so that it doesn't attempt to return the handle.Here's a modified version of your function:
function fcn(a, b, c, d)
%#codegen
rectangle('Position', [a, b, c, d]);
axis([0 10 0 10]);
end
If you need to return some specific information about the rectangle, such as its position or size, you can adjust the function accordingly. Here's an example of returning the position vector:
function pos = fcn(a, b, c, d)
%#codegen
rectangle('Position', [a, b, c, d]);
axis([0 10 0 10]);
pos = [a, b, c, d]; % Return the position vector
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1814018/image.png)
Hope it helps.
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!