Subscript indices must either be real positive integers or logicals. Error!

1 次查看(过去 30 天)
I keep getting the same message no matter what I do, and I'm not sure in what line the error is.
My code:
for i=1:length(finalx(i)); row= ceil(finalx(i)*(10000+diffy)); col= ceil(finaly(i)*(10000+diffx)); widthless=3; widthmore=3; valuer(i)= sum(B((row-widthless):(row+widthmore),col)); end figure(7) plot(finaly*(10000+diffx), finalx*(10000+diffy-widthless),'*m',... finaly*(10000+diffx),finalx*(10000+diffy+widthmore),'.r')
for n=1:size(Eev,2); %size (Eev,2) will give the number of columns in matrix Eev nproton(1,n)=valuer(n)/interp1(Ecal,pslcal,Eev(n),'cubic'); end
figure(107);plot(Eev/1E6,nproton(1,:)); xlabel('Energy (MeV)');ylabel('nproton'); title 'nbr of proton vs. Energy (MeV)' text(1,40,'CP, 0.65 micron, 1200 V,PD signal=800mV, #1');

回答(1 个)

Iain
Iain 2014-2-19
(row-widthless):(row+widthmore)
Thats probably giving you a negative (or zero) number which you're trying to use as an index.
max([row-widthless; 1]):(row+widthmore)
That should fix it, but you may have a similar problem when row+widthmore gets to be bigger than the maximum width in your array.
  1 个评论
Lujain
Lujain 2014-2-19
I changed it into: valuer(i)= sum(B(max([row-widthless;1]):(row+widthmore),col));
also, tried something like: valuer(i)= sum(B(max([row-widthless;1]):(row+widthmore))); and its still giving me the same message :/

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by