MATLAB Answers

0

Index exceeds matrix dimensions ERROR

Asked by Mariaelena on 24 Jul 2019
Latest activity Edited by Jan
on 24 Jul 2019
Hi, can somebody figure out why I get this error message? Thank you very much!
Index exceeds matrix dimensions.
Error in gidilm1>localPlot (line 244)
line_h=line(t,XYData(:,cb),'UserData',cb,'ButtonDownFcn','gidilm1
line','Tag','lin','Color',col)%,'Marker','+');
Error in gidilm1 (line 95)
line_h(i)=localPlot(i,ax,colory(i-cbi+1,:));
Error while evaluating UIControl Callback
function line_h=localPlot(cb,ax,col)
global XYData t
cb;
ax;
col;
line_h=line(t,XYData(:,cb),'UserData',cb,'ButtonDownFcn','gidilm1 line','Tag','lin','Color',col)%,'Marker','+');
axis(ax)
%axis([0 19.8 0.05 0.5])
axe=gca
%set(axe,'Xtick',[0:2:40])
xlabel('TEMPS (h)')
ylabel('DO')
% figure
for i=cbi:cbf
line_h(i)=localPlot(i,ax,colory(i-cbi+1,:));
end
ts=ax(1):50:ax(2)+60;
dos=doseuil.*(ones(1,length(ts)));
line(ts,dos,'Color','b')

  3 Comments

Torsten
on 24 Jul 2019
I don't see a line where you assign values to "cbi" or "cbf".
Here is the problem:
XYData(:,cb)
But we don't know the values of those variables. What is the result of
whos XYData
cb
case 'fboxcb'
fileIndex=get(gcbo,'Value');
fileList=get(gcbo,'String');
filename=fileList{fileIndex};
XYData=[];
XYData=LocalGetData(filename);
size(XYData);
[imax jmax]=size(XYData);
t=XYData(:,1)./60;
XYData(:,1)=[];
size(t);
case 'regvcb'
% Restoration of the threshold times
j=0;
% [t(1:100) XYData(1:50,cbi:cbf)]
% [t XYData(:,1)];
for cb=cbi:cbf
k=0;
j=j+1;
i=4;
l=[];
while k <1
if XYData(i,cb)>dosupseuil
k=1;
end
if and(XYData(i,cb)>doinfseuil,XYData(i,cb)<dosupseuil)
l=[l;i];
end
if i==imax
l=i-2:i-1;
break
end
i=i+1;
end
yspline=XYData(l,cb)
xspline=t(l)
P=polyfit(yspline,xspline,1);
TD(j)=polyval(P,doseuil);
%TD(j)=t(i);
end
TD;

Sign in to comment.

1 Answer

Answer by Jan
on 24 Jul 2019
Edited by Jan
on 24 Jul 2019

Using global variables is a bad programming style. It impedes the debugging massively. It is hard to find out, which code has set the values of t, XData and cb the last time. Obviously these values contain a problem. Prefer to use input and output arguments instead. For sharing variables between callbacks: https://www.mathworks.com/matlabcentral/answers/?term=share+variables+between+callbacks
What is the meaning of these lines:
cb;
ax;
col;
?

  0 Comments

Sign in to comment.