Index exceed the number of array elements

1 view (last 30 days)
Maciej Irlik
Maciej Irlik on 2 Feb 2021
Answered: Stephen23 on 2 Feb 2021
Hi,
I have problem with execute the last 3 line of my code. I define in excel Vref1 table with 6 elements. Using funciton lenght(V_ref) MATLAB correctly define that length of this array is 6 but during execution function v = find(V_ref == V_Target):max(V_ref) it rewrite v to 7 and this cause this issue.
Any idea?
V_ref = xlsread('Vref1',1,'A:C');
V_ref = Vref(:,1);
for v = 1:length(V_ref)
A_brake1(v) = Kdry_rst(v)*(Kwet_rst(v) + M_NVAVADH*(1-Kwet_rst(v)))*A_brake2(v);
end
for d = 1:length(d_line)
if grad(d) >= 0
A_gradient(d) = g*grad(d)/(1000+10*M_rotating_max);
else
A_gradient(d) = g*grad(d)/(1000+10*M_rotating_min);
end
end
for v = 1:length(V_ref)
for d = 1:length(d_line)
A_safe(v,d) = A_brake_safe(v) + A_gradient(d);
A_expected(v,d) = A_brake_service + A_gradient(d);
end
end
for v = find(V_ref == V_Target):max(V_ref)
V(v) = V_ref(v);
% EBD(v) = (((V(v)/3.6)^2)-((V_Target/3.6)^2))/(2*A_safe(v,1));
end

Answers (1)

Stephen23
Stephen23 on 2 Feb 2021
tmp = find(V_ref == V_Target):max(V_ref);
for v = reshape(tmp,1,[]);

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!