Matlab keeps saying this matrix is undefined?
Show older comments
function [Crash,D_min] = crash_func (t, x, P_S, P_N, N_S, N_N)
% D_min: minimum distance between NS and E cars
% x is position vector for a single E car
% P_S and P_N are position vectors for S and N cars
% N_S and N_N are number of S and N cars
[dangerT,dangerCol] = find(x>= -5 & x<= 5);
for i = 1:N_S-1
for j = 1:numel(dangerT)
d_ES(i,j) = find_d(x(j),0,-2, P_S(j,i));
end
end
for i = 1:N_N-1
for j = 1:numel(dangerT)
d_EN(i,j) = find_d(x(j),0,2, P_N(j,i));
end
end
d_ES = d_ES';
d_EN = d_EN';
mins = [min(d_ES),min(d_EN)];
D_min = min(mins);
% if minimum distance between cars is less than 2*radius
Crash = false;
if D_min < 3
Crash = true;
end
end
function [d] = find_d (x1,y1,x2,y2)
d = sqrt((y2-y1)^2+(x2-x1)^2);
end
I keep getting an error that says d_EN and d_ES are undefined when the lines d_ES = d_ES' and d_EN = d_EN' are run
1 Comment
Roger Stafford
on 30 Apr 2017
Edited: Roger Stafford
on 30 Apr 2017
I can only guess at the trouble, but if ‘find_d’ is attempting to find certain elements in P_S and P_N, and if it fails to do so or if it finds multiple copies, then d_ES and d_EN will not be properly defined everywhere.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!