Simulation stopped due to out of bounds error

1 view (last 30 days)
Hi, I'm running the next code into embedded matlab block from simulink, but when I run it, I have the next error message Simulation stopped due to out of bounds error, Enable debugging to pinpoint the location of the error.
I did enable debugging and it keeps pinpoint the line of D(s,:) = inf , until I stopped appears the same error message Simulation stopped due to out of bounds error. Block Embedded MATLAB Function (#19) While executing: none.
Can anyone please help me with this..
x=(54,2);
function D = distmat(X)
%DISTMAT Compute euclidian distance matrix from coordinates
[n,dim] = size(X);
D = zeros(n);
for j = 1:n
for k = 1:dim
v = X(:,k) - X(j,k);
D(:,j) = D(:,j) + v.*v;
end
end
D = sqrt(D);
%--------------------------------------------------------------
function p = greedy(s,D)
n = size(D,1);
p = zeros(1,n,'uint16');
p(1) = s;
for k = 2:n
D(s,:) = inf;
[junk,s] = min(D(:,s));
p(k) = s;
end
  3 Comments
Emmanuel Luevano
Emmanuel Luevano on 29 Nov 2012
btw, in the matlab promt appear the next message
Runtime error: Expected an integer value, found non-integer variable s with value 0.0318328.
the function greedy is called by the next function
eml.extrinsic('exchange2');
Lmin = inf;
L = 0;
pmin = uint16(0);
for k = 1:m
% Nearest neighbour tour
p1 = greedy(s(k),D);
% Improve tour by 2-opt heuristics
[p,L] = exchange2(p1,D);
% Keep best tour
if L < Lmin
Lmin = L;
pmin = p;
end
end
% Output
p2 = double(pmin);
L1 = Lmin;
feel free to do any comment, regards!
Kaustubha Govind
Kaustubha Govind on 29 Nov 2012
Ah! So that's the problem. You need to make sure 's' is an integer. You can't index with a non-integer. For example, you can't do:
x = zeros(2);
y = x(0.2);

Sign in to comment.

Answers (0)

Categories

Find more on Event Functions 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!