Error: Index exceeds matrix dimensions.

Hi, Why do I get this message "Index exceeds matrix dimensions."??. At first I thought it was because that I named a variable with function name then I used "exist checkname " function to check and it gave me 0. So I'm still confused what might be the problem!
Code:
for k= 1: length(finalx); row3= ceil(finalx(k)*(10000+diffy3)); col3= ceil(finaly(k)*(10000+diffx3)); widthless= 3; widthmore=3; valuer3(k)= sum(B3((row3-widthless):(row3+widthmore),col3)); end figure(16) plot(finaly*(10000+diffx3),finalx*(10000+diffy3-widthless),'.g',... finaly*(10000+diffx3),finalx*(10000+diffy3+widthmore),'.r')

3 件のコメント

Image Analyst
Image Analyst 2014 年 2 月 20 日
編集済み: Image Analyst 2014 年 2 月 20 日
You need to tell us the entire error message. That means ALL THE RED TEXT. Don't snip or paraphrase. Then, whatever variables you see on that line, do a whos on:
whos finalx
whos diffy3
and so on. Then tell us what you find. One of the indexes will be more than the size of the array.
Lujain
Lujain 2014 年 2 月 20 日
So this is the entire message I get when I run the code: "Warning: Images with a MinIsWhite grayscale interpretation and more than eight bits per sample will not be transformed into a MinIsBlack grayscale interpretation. The pixel data will be returned as-is. Index exceeds matrix dimensions." Apparently the problem is in figure 116, as I got all the other figures.
Code: A2= imread('CPOL_0.65um1200V_cropednrotated4.tiff'); F2= double(A2);
S2= (2.^(16-F2));
diffx3= 41.5; diffy3= 30; B3=(10.^(5*S2)/(2^16-0.5));
figure(16) imagesc(log(B3)); colormap(gray); axis equal; hold on;
figure(16) plot(finaly*(10000+diffx3),finalx*(10000+diffy3),'.g',diffx3,diffy3,'.r');
for k= 1: length(finalx); %remember this is a samll k. row3= ceil(finalx(k)*(10000+diffy3)); col3= ceil(finaly(k)*(10000+diffx3)); widthless= 3; widthmore=3; valuer3(k)= sum(B3((row3-widthless):(row3+widthmore),col3)); end figure(16) plot(finaly*(10000+diffx3),finalx*(10000+diffy3-widthless),'.g',... finaly*(10000+diffx3),finalx*(10000+diffy3+widthmore),'.r') for N= 1:size(Eev,2); nproton3(4,N)= (valuer3(N))/(interp1(Ecal,pslcal,Eev(N),'cubic')); end
figure(116) plot((Eev/1E6),nproton3(4,:)); xlabel('Energy(Mev)'); ylabel('number of protons'); title('number of protons VS Energy(MeV)'); text(1,40,'CP, 0.65 micron, 1200 V,PD signal=1200mV,600 #4');
Lujain
Lujain 2014 年 2 月 20 日
Thanks for the link

サインインしてコメントする。

回答 (1 件)

Dishant Arora
Dishant Arora 2014 年 2 月 20 日

1 投票

dbstop if error
try debugging your code using dbstop, it will tell when actually this error occurs.

2 件のコメント

Lujain
Lujain 2014 年 2 月 20 日
編集済み: Lujain 2014 年 2 月 20 日
Thanks I read this already somewhere else and I used it, but nothing happens :/ ! can you tell me what is the syntax? or put an example.
Dishant Arora
Dishant Arora 2014 年 2 月 20 日
編集済み: Dishant Arora 2014 年 2 月 20 日
type that in your command window and then run your code.
dbstop if error
YourScriptName % or run it directly from the editorwindow
Check out for your loop variables in the workspace after that

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2014 年 2 月 20 日

編集済み:

2014 年 2 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by