Hi!.Can anyone please help me how to get rid of this errors.I herby attach my code and the errors.

조회 수: 2 (최근 30일)
function [xfar_in,yfar_in] = fartheta(y_veh, x_veh)
% c=0.0100;
% error_in=0;
% amplitude=1;
% xfar_in=zeros(2,1);
% yfar_in=zeros(2,1);
% xin_new=zeros(2,1);
% yin_new=zeros(2,1);
% slope_in=zeros(2,1);
% slope_curve_in=zeros(2,1);
x_save = zeros(2,1);
y_save = zeros(2,1);
% coder.varsize('x_save',[1, 2 * length(x_veh)]);
% coder.varsize('y_save',[1, 2 * length(y_veh)]);
% error_in = 0.001;
% xin_new = x_veh;
% yin_new = y_veh;
for i = 1:length(x_veh)
xin_new = x_veh(i);
yin_new = y_veh(i);
error_in = 0.001;
while error_in>=0
xin_new = xin_new + 0.01;
yin_new = 1*sin(2*pi*xin_new/25);
slope_in = (yin_new-y_veh)/(xin_new-x_veh);
slope_curve_in = (1*2*pi/25)*cos(2*pi*xin_new/25);
error_in = slope_curve_in-slope_in;
xin_new = xin_new+0.01;
end
x_save = [x_save;xin_new];
y_save = [y_save;yin_new];
end
xfar_in = x_save;
yfar_in = y_save;
% xfar_in = xin_new;
% yfar_in = yin_new;
% d_in = sqrt(((x_veh-xfar_in)^2) + ((y_veh-yfar_in)^2));
%
% m1=tan(hdg);
% m2=(y_veh-yfar_in)/(x_veh-xfar_in);
% farangle=atan((m1-m2)/(1+m1*m2));
  댓글 수: 1
Joe Jones
Joe Jones 2022년 7월 12일
Dear
Did you solve this problem ?
I also had this problem recently. "An error occurred while propagating data type 'double' through 'adrc/cg_adrc'". (the last problem in the attached picture 'erroes.JPG')
Hope you can help me if possible. Thank you.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 6월 30일
You need to preallocate the output variable and assign into the appropriate locations in it, instead of dynamically growing your array.
  댓글 수: 10
Sanjal C C
Sanjal C C 2018년 6월 30일
Yeah really sorry.I could not see your comments and I have attached previously my updated code.
Walter Roberson
Walter Roberson 2018년 6월 30일
Maybe you want something like,
function [xfar_in,yfar_in] = fartheta(y_veh,x_veh,error_in)
nveh = length(x_veh);
x_save = zeros(1, nveh);
y_save = zeros(1, nveh);
for i = 1:nveh
xin_new = x_veh(i);
yin_new = y_veh(i);
error_in = 0.001;
while true
xin_new = xin_new + 0.01;
yin_new = 1*sin(2*pi*xin_new/25);
slope_in = (yin_new-y_veh(i)) ./ (xin_new-x_veh(i));
slope_curve_in = (1*2*pi/25)*cos(2*pi*xin_new/25);
error_in = slope_curve_in-slope_in;
if error_in <= 0
break;
end
xin_new = xin_new+0.01;
end
x_save(1,i) = xin_new;
y_save(1,i) = yin_new;
end
and here calculate xfar_in and yfar_in

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by