2015-02-05 29 views
0

所以這是我的代碼:如何刪除行,而不在MATLAB用break

in=-8:8; 
%calculate z 
[h,k,l]=meshgrid(in); 
z = (h.^2 + k.^2 + l.^2); 

%sort absolute values ascending, which allows to use unique 
ac=sort(abs([h(:) k(:) l(:)]),2); 
%use unique to identify duplicates 
[f,g,p]=unique(ac,'rows'); 
%count 
cnt=histc(p,1:max(p)); 
% create a matrix with all vectors 
disp([h(g),k(g), l(g),z(g),cnt]) 

我只是想刪除或終止含ž> 59,我不能用破,因爲它只能在行循環或while循環,那麼我可以使用什麼其他命令?謝謝。

+0

中使用的基體要刪除的行? – thewaywewalk 2015-02-05 18:56:38

+0

一個已經排序的矩陣,並有一列 – matlabnewbie 2015-02-05 18:59:14

+0

,所以你顯示的那個,如'輸出= [h(g),k(g),l(g),z(g),cnt]'? – thewaywewalk 2015-02-05 19:00:16

回答

1

我猜你想這樣的:

%// your output matrix you want to filter 
output = [h(g),k(g), l(g),z(g),cnt]; 
%// delete rows containing z > 59 (z is the 4th column) 
filtered_output = output(output(:,4) <= 59,:) 
+0

是的,它的作品謝謝:) – matlabnewbie 2015-02-05 19:07:30

相關問題