フィルターのクリア

Simulation stopped due to out of bounds error

3 ビュー (過去 30 日間)
Emmanuel Luevano
Emmanuel Luevano 2012 年 11 月 28 日
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 件のコメント
Emmanuel Luevano
Emmanuel Luevano 2012 年 11 月 29 日
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 2012 年 11 月 29 日
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);

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by