Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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');

Risposte (1)

Iain
Iain il 19 Feb 2014
(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 Commento
Lujain
Lujain il 19 Feb 2014
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 :/

Accedi per commentare.

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by