In an assignment A(I) = B, the number of elements in B and I must be the same

I have written a simple Matlab s-function program to calculate nearest coordinates in a parallelogram, . the code is as follows:
function sys = mdlOutputs(t,x,u)
g=u(1);
h=u(2);
global m;
global n;
global m1;
global m2;
global n1;
global n2;
m=0;
if (g<m)
m1=m-1;
m2=m;
else
m=m+1;
end
n=0;
if (h<n)
n1=n-1;
n2=n;
else
n=n+1;
end
M1=m1;
M2=m2;
N1=n1;
N2=n2;
sal(1)=M1;
sal(2)=M2;
sal(3)=N1;
sal(4)=N2;
sys=sal;
% End of mdlOutputs.

4 Comments

Can you also please give a list of input and global parameters that will cause the error? You are leaving a bit too much guesswork up to us. Better yet, distill the code down to the simplest possible form that exhibits the error. (This distillation process, in itself, often identifies the problem.)
I would hazard the guess that at least one of the globals, m1, m2, n1, or n2 is not a scalar when 'mdlOutputs' is called and that this causes one of the four lines defining 'sal' to produce this error message.
And of course give us the error message. This means ALL THE RED TEXT, not some small snippet clipped out of it like you did. I mean, how can we even know what line gave the error if you did not include the part of the error message that gives that information, and you did not give use enough information to run your code, and you did not attach your m-file for the function and the unit test for it? By the way, please read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
In the below hexagon figure, the parallelogram of coordinate (g,h) is the base plane on which I am working on.
In this plane (g,h) is the reference plane & input of the coding. By this simple logic, if reference coordinates is fed in to the system, all the four coordinates will be found/calculated & that is the idea of the s function code.
For an example: If (g,h) is (1.15,0.69) then the four coordinate points (m1,n1)=(1,0)
(m2,n1)=(2,0)
(m1,n2)=(1,1)
(m2,n2)=(2,2)
will be found & thats the idea.
attached pic of error, model file & parallelogram inside hexagon.. guidances/helps to eradicate this problem are most welcome

Sign in to comment.

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products

Asked:

on 23 Dec 2013

Edited:

on 24 Dec 2013

Community Treasure Hunt

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

Start Hunting!