Simulink Matlab Function size mismatch error

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

When I comment the "igtby=zeros(1,34);" part, then I get this error:
"Error in default port dimensions function of S-function 'M1_Hatti_TrenSayisiArttirmaDenemesi/Model ayrık/TrendekiBosYer_TrendenInenler_FnBlck/MATLAB Function1'. This function does not fully set the dimensions of output port 3"
But this block only have 2 outputs, where does the 3rd output come? I think the block is corrupted, but when I create a fresh one, it behaves the same.
Any thoughts?
update:
Problem is solved, but how??
igtby is obviously an output and connected to something. I removed the variable from output table, then I tried to run the simulation. Bingo, it worked. Than step by step, first igtby becomes an output again, but it is not connected to anything. Again, successfully completed the simulation. Then, finally, connected the igtby output to the same place before (everything is exactly same as I get the error message). Bammm, still worked. Meaningless, ridiculous, but now the exact same combination works. non-deterministic error I think, Hope doesn't decide to give same error again.
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

Sign in to comment.

Answers (0)

Products

Release

R2018b

Asked:

on 14 Nov 2018

Commented:

on 22 Sep 2021

Community Treasure Hunt

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

Start Hunting!