Index exceeds matrix dimensions.

2 ビュー (過去 30 日間)
Christian Kolb
Christian Kolb 2017 年 8 月 11 日
コメント済み: Adam 2017 年 8 月 11 日
Can someone tell me the error that is here ?
%dicomread enthaelt 512x512 matrix mit 16Bit Grau Werten. Keine mm Ortspositionen
[CT,map,alpha] = dicomread('CT000018.dcm');
CtInfo = dicominfo('CT000018.dcm');
%Nur Z Werte in array
ROIz = Roi_xyz(1,3:3:end)';
%Finde Index bestimmter Schicht, Beispiel -63, besser aus DCM Header CT
%Slice Location, dort Wert fuer Bsp -63
ROIz = find(ROIz(:,1) == CtInfo.SliceLocation); %Was wenn mehrere Treffer???
%CtPixel = CtInfo.PixelSpacing(1);
%Ursprung CtInfo.ImagePositionPatient
%Umrechnung mm in Pixel
Roi_pixel = (Roi_xyz)/CtInfo.PixelSpacing(1);
Roi_pixel(:,3:3:end) = Roi_xyz(:, 3:3:end);
%Ursprungsverschiebung xy und auf ganze Pixel runden
Roi_pixel(:,1:3:end) = round(Roi_pixel(:,1:3:end) - CtInfo.ImagePositionPatient(1)/CtInfo.PixelSpacing(1));
Roi_pixel(:,2:3:end) = round(Roi_pixel(:,2:3:end) - CtInfo.ImagePositionPatient(2)/CtInfo.PixelSpacing(1));
%Eine Schicht ROI in 512x512 Matrix umrechnen
Roi_pixel512 = uint16(zeros(512,512));
Roi_pixelXY = [Roi_pixel(:,(ROIz*3-1)),Roi_pixel(:,(ROIz*3-2))];
Roi_pixelXY(isnan(Roi_pixelXY(:,1)),:) = [];
Roi = roipoly(CT,Roi_pixelXY(:,2),Roi_pixelXY(:,1));
Roi = uint16(Roi);
%Vektor Roi_CT fuer Histogram in 16bit Grau
Roi_CT = CT(Roi==1);
  1 件のコメント
Adam
Adam 2017 年 8 月 11 日
The error is that you are trying to index into a matrix using an index that is larger than the size of the matrix in that dimension. More than that it is difficult to say since you give no information on which line causes the error.
As José-Luis says though, the debugger makes this kind of thing easy. I come across this error regularly and never have any trouble locating it because I use the debugger, which illuminates the problem instantly. Whether it is then easy to fix or not depends entirely on what is causing the over-sized index. It may be trivial or it may be a fundamental algorithmic problem.

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

回答 (1 件)

José-Luis
José-Luis 2017 年 8 月 11 日
Type
dbstop if error
in the command line.
Run your code. Look at the size of the variables in the operation that fails. The error should become evident.
This gets asked many times a day in this forum, have you tried looking at those other answers?
Please learn to use the debugger, it will save you a lot of time in the future.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by