Simulink Matlab Function size mismatch error
Show older comments
Hello all,
I use the following matlab function in a Simulink Matlab Function.
function [igtby, igty] = fcn(input1, input2, ..., input n)
igtby=zeros(1,34);
igty=zeros(1,34);
While compiling, I get the following error, it drives me crazy:
"Size mismatch (size [34 x 1] ~= size [1 x 34]). The size to the left is the size of the left-hand side of the assignment. Function 'Model ayrık/TrendekiBosYer_TrendenInenler_FnBlck/MATLAB Function' (#10209.126.131), line 2, column 1: "igtby" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error"
igtby is not an input, it is not written anywhere. The output properties are normal as you can see in the following figure. What am I doing wrong and not finding it out? By the way diagnostic report says exactly same as the error, sizes mismatch.

3 Comments
Berkin Birol
on 14 Nov 2018
Berkin Birol
on 15 Nov 2018
Caspar Hanselaar
on 22 Sep 2021
Like your problem, I encountered a similar issue in R2021a:
An element-wise multiplication in the form of the following:
function bbox_interp = interpolate_bounding_box2(bbox_past,time_past,bbox_future,time_future,target_time)
% function to linearly interpolate bounding box (bbox) position
ratio = (target_time-time_past)/(time_future-time_past);
bbox_interp = bbox_past + (bbox_future - bbox_past).*ratio;
end
Gave the following error:
Size mismatch detected: [4][2] ~= [1][1]
I managed to track it down to it interpreting the 'ratio' as a [1][1] matrix, rather than a scalar variable.
Solved it by accessing the first entry of the [1][1] matrix;
function bbox_interp = interpolate_bounding_box2(bbox_past,time_past,bbox_future,time_future,target_time)
% function to linearly interpolate bounding box (bbox) position
ratio = (target_time-time_past)/(time_future-time_past);
bbox_interp = bbox_past + (bbox_future - bbox_past).*ratio(1);
end
Answers (0)
Categories
Find more on String 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!