如何在不使用matlab中的break的情况下删除行
How to delete rows without using break in matlab
所以这是我的代码:
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])
我只想删除或终止包含 z>59 的行,我不能使用 break,因为它只能在 for 循环或 while 循环中使用,那么我还可以使用什么其他命令?谢谢。
我猜你想要这个:
%// 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,:)
所以这是我的代码:
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])
我只想删除或终止包含 z>59 的行,我不能使用 break,因为它只能在 for 循环或 while 循环中使用,那么我还可以使用什么其他命令?谢谢。
我猜你想要这个:
%// 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,:)