Port width mismatch in SIMULINK - matlab

While i was coding matlab function module, i get an error message as seen below which gives a port mismatch error.
ERROR MESSAGE: Port width mismatch. Input 'u' expects a signal of size 1. The signal received is of size 6.
Can you help me on coding.
SIMULINK SCHEME:
MATLAB FUNCTION:

Related

Invalid setting for parameter 'Gain'

I am trying to create a simple controller, but keep receiving an error for the gain block stating that there is an undefined variable 'u'. I do not understand Simulink well and I am just trying to replicate an old homework problem right now. The code I have here was provided as a solution, but I still receive the error when I try to run it. Any insights as to what might be going on?
I= 10; Wl= 5; k= 2; J= 1;
%set initial conditions
thetaIC= 0; phiIC= 0; x0= zeros(4,1);
%fix theta= 0, check output
[xe, ue]= trim('Ex3_System',x0,0,x0,1)
[A,B,~,~]= linmod('Ex3_System', xe, ue)
%choose your desired poles
p= linspace(-1.2,-1.5,4)
%recall the minus sign
K= -acker(A,B,p)
%perturb initial condition
thetaIC= deg2rad(5);
sim('Ex3_Controller');
Invalid setting in 'Ex3_Controller/Gain' for parameter 'Gain'. Caused
by:
Error using hw12 (line 57)
Error evaluating parameter 'Gain' in 'Ex3_Controller/Gain'
Error using hw12 (line 57)
Undefined function or variable 'u'.
Error using hw12 (line 57)
Variable 'u' does not exist.
Suggested Actions:
• Load a file into 'Base Workspace'. - Fix
• Create a new variable. - Fix
Update: After removing the u term from the gain block, I received a different error:
Error using hw12 (line 57)
Error in port widths or dimensions. Output port 1 of 'Ex3_Controller/Gain' is a one dimensional vector with 4 elements.
Error using hw12 (line 57)
Error in port widths or dimensions. Input port 1 of 'Ex3_Controller/Model1' is a one dimensional vector with 1 elements.
The Gain block takes the value of the input signal and multiplies it by the value of the gain. In your case the gain is K and that is all you need to put into the gain block (i.e. remove the *u, Simulink handles that for you.)
Once that is done, the dimension error you are getting is because your controller requires u to be a scalar, but you are feeding a 4 element vector into it. You need to change the appropriate parameter of the Gain block so that it does a matrix multiplication, taking the 4-by-1 matrix K and (matrix) multiplying it with the 4 element "out" signal to produce a scalar.

Simulink signal for array message passing

I want to publish a 2-dimensional array from a MATLAB function in Simulink to a ROS topic.
I have followed this tutorial where an example is given for a geometry_msgs/Point. However, I want to use std_msgs/Float32MultiArray which is a bit more complex:
I cannot even make it compile with Data and DataOffset only:
I get the following error:
Error in port widths or dimensions. Output port 1 of '.../MATLAB Function' is a [1x10] matrix.
Error in port widths or dimensions. Input port 2 of '.../Bus Assignment' is a one dimensional vector with 128 elements.

Error using bsxfun Mixed integer class inputs are not supported

I'm working on a project on neural network and my working medium is Matlab. While running the following code:
net=train(net, feat_mat, gt_mat);
The neural network that I've used is a ffnn with 3 hidden layer. The highest value in feat_mat is 255 and the lowest is 0. The highest value in gt_mat is 1 and the lowest is 0. feat_mat has 5x423500 uint8 value and gt_mat has 1x423500 uint8.
I got the following error:
Error using bsxfun
Mixed integer class inputs are not supported.
Error in mapminmax.apply (line 6)
Error in nnet.mode.matlab.processInput (line 7)
Error in nnet.mode.matlab.processInputs (line 12)
Error in nncalc.preCalcData (line 16)
Error in nncalc.setup1>setupImpl (line 176)
Error in nncalc.setup1 (line 16)
Error in nncalc.setup (line 7)
Error in network/train (line 357)
I don't understand why this error is occuring. Any help would be appreciated. Thanks.
P.S: I've searched google and other questions at this site but none of them are relevant to mine.
As detailed in the error, train relies on bsxfun, which doesn't support mixed integer classes.
Your inputs are uint8 arrays, i.e. mixed integers, so train falls over.
To get around this, simply convert the inputs to doubles
net = train( net, double(feat_mat), double(gt_mat) );

MatLab 2014a Fuzzy Toolbox Error

I am trying to devise a Sugeno fuzzy system using the fuzzy GUI - for some reason when I add more than one output variable I get errors:
Error using length
Too many input arguments.
Error in addvar (line 76)
for ct=1:length(out.output.mf)
Error in fuzzy (line 746)
fis=addvar(fis,varType,'',[0 1],'init');
Error while evaluating uimenu Callback
I'm using 2014a on a Mac running Mavericks. To note, I also have 2013a installed on a MacBook and tried adding the same input and output variables and I get them same error messages.
If you add more than one output variable, then try and add input variable the above messages are then displayed within the command prompt.

MSER features detection not working in matlab

Why is that whenever I try to use detectSURFFeatures(img) with a binary image in matlab gives me proper points but whenever I use detectMSERFeatures(img) with the same binary image gives me error instead of pointing some valid regions?
ERROR:
Error using detectMSERFeatures
Expected input number 1, I, to be one of these types:
uint8, int16, uint16, single, double
Instead its type was logical.
Error in detectMSERFeatures>parseInputs (line 75)
validateattributes(I,{'uint8', 'int16', 'uint16', ...
Error in detectMSERFeatures (line 64)
[Iu8, params] = parseInputs(I,varargin{:});
Try this:
make image 2 double first by using img=im2double(img);
then feed it to MSER
detectMSERFeatures(img)
detectMSERFeatures does not accept logical inputs, as stated in the documentation and in the error you are receiving. detectSURFFeatures does. I don't know if there's a specific reason why, as I'm not familiar with the limitations of the different algorithms.
You could simply convert your binary image to one of the types listed, and run MSER on it:
detectMSERFeatures(double(img));