フィルターのクリア

How can I delete the rows and columns of a 3D matrix? I tried to use the following Px((1:(Col​​umn1-1)),​:​,i)=[] but I am getting this error "A null assignment can have only one non-colon index." How can I correct it?

5 ビュー (過去 30 日間)
clear all
clc
dicomlist = dir(fullfile(pwd,'SER_7_Dicoms','*.dcm'));
for cnt = 1 : numel(dicomlist)
I{cnt} = dicomread(fullfile(pwd,'SER_7_Dicoms',dicomlist(cnt).name));
% Each{cnt} = char(dicomlist(cnt).name)
% %info = dicominfo('MR03318.dcm');
% %dicominfo(dicomlist(cnt).name)
end
for cnt = 1 : numel(dicomlist)
info{cnt} = dicominfo(fullfile(pwd,'SER_7_Dicoms',dicomlist(cnt).name));
end
for i = 1:length(info)
Rows(i) = double(info{1,i}.Rows);
Columns(i) = double(info{1,i}.Columns);
Pixel_Spacing(:,i) = double(info{1,i}.PixelSpacing); %in mm/pixel
Pixel_Spacing_x(:,i) = double(info{1,i}.PixelSpacing(1));
Pixel_Spacing_y(:,i) = double(info{1,i}.PixelSpacing(2));
Patient_Position(:,i) = double(info{1,i}.ImagePositionPatient);
Sx(:,i) = double(info{1,i}.ImagePositionPatient(1));
Sy(:,i) = double(info{1,i}.ImagePositionPatient(2));
Sz(:,i) = double(info{1,i}.ImagePositionPatient(3));
Image_Orientation(:,i) = double(info{1,i}.ImageOrientationPatient);
F12(:,i) = double(Image_Orientation(4,i));
F22(:,i) = double(Image_Orientation(5,i));
F32(:,i) = double(Image_Orientation(6,i));
F11(:,i) = double(Image_Orientation(1,i));
F21(:,i) = double(Image_Orientation(2,i));
F31(:,i) = double(Image_Orientation(3,i));
F1(:,i) = [F11(:,i) F21(:,i) F31(:,i)];
F2(:,i) = [F12(:,i) F22(:,i) F32(:,i)];
n(:,i) = cross(F1(:,i),F2(:,i))%vector normal to the plane
magnitude(:,i) = sqrt(n(1,i)^2+n(2,i)^2+n(3,i)^2);
n_normalized(:,i) = n(:,i)/magnitude(:,i);
V1 = 202.0;
V2 = 220.0;
H1 = 80.0;
H2 = 120.0;
Row1(:,i) = round(V1/Pixel_Spacing_y(:,i));
Row2(:,i) = round(V2/Pixel_Spacing_y(:,i));
Column1(:,i) = round(H1/Pixel_Spacing_x(:,i));
Column2(:,i) = round(H2/Pixel_Spacing_x(:,i));
Delta_r_ROI(:,i) = double(Pixel_Spacing_x(:,i));
Delta_c_ROI(:,i) = double(Pixel_Spacing_y(:,i));
%fileID(i) = fopen(sprintf('New%d.dat',i),'w');
A(:,:,i) = [(F11(:,i)*Delta_r_ROI(:,i)) (F12(:,i)*Delta_c_ROI(:,i)) 0 Sx(:,i); F21(:,i)*Delta_r_ROI(:,i) F22(:,i)*Delta_c_ROI(:,i) 0 Sy(:,i); F31(:,i)*Delta_r_ROI(:,i) F32(:,i)*Delta_c_ROI(:,i) 0 Sz(:,i);0 0 0 1];
subImage(:,:,i) = I{1,i}(Row1(:,i):Row2(:,i), Column1(:,i):Column2(:,i));
%figure(i), imshow(subImage(:,:))
for r = (Row1(:,i)):(Row2(:,i))
for c = Column1(:,i):Column2(:,i)
B(:,i) = [r;c;0.0;1.0];
P(:,:,i) = A(:,:,i)*B(:,i);
Px(c,r,i)=P(1,:,i);
Py(c,r,i)=P(2,:,i);
Pz(c,r,i)=P(3,:,i);
%disp([r c])
end
end
Px((1:(Column1-1)),:,i)=[];
Py(1:(Column1-1),:,i)=[];
Pz(1:(Column1-1),:,i)=[];
Px(:,1:(Row1-1),i)=[];
Py(:,1:(Row1-1),i)=[];
Pz(:,1:(Row1-1),i)=[];

回答 (2 件)

the cyclist
the cyclist 2016 年 5 月 24 日
Suppose you have the 2-dimensional matrix
A = [1 4 7;
2 5 8;
3 6 9]
and try the command
A(3,3) = []
You are telling MATLAB to remove the 9. But that makes no sense. What is left is not a matrix. You could insert some other value there, such as
A(3,3) = NaN
but you cannot just remove it.
You are trying to do the same thing in your array.
  1 件のコメント
HH0825
HH0825 2016 年 5 月 24 日
It works for a 2D array for instance:Px((1:(Column1-1),:). However when I have the loop that introduces the index i my Px matrix becomes 3D and therefore the syntax does not work anymore. When I use Px((1:(Column1-1)),:,i)=NaN it works. But I don't want to have NaN in my data output.

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


Image Analyst
Image Analyst 2016 年 5 月 24 日
You have to erase a whole plane, not just some columns.
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 5 月 24 日
Px((1:(Column1-1)),:,:)=[]
You might wanting to loop over the third dimension, but MATLAB does not know that Column1 is not going to change on the other panes and so does not know that "eventually" it would not be a "ragged array". And if you know that Column1 is not going to change then just do it all at once like the above.

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

カテゴリ

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