How to delete rows in matlab
1 次查看(过去 30 天)
显示 更早的评论
So guys i need your help this is my code:
a=3;
lamda=1.54;
in=-3:3;
%calculate z
[h,k,l]=meshgrid(in);
d = sqrt((a.^2)/(h.^2 + k.^2 + l.^2));
z = (lamda./(2*d));
%sort absolute values ascending, which allows to use unique
ac=sort(abs([h(:) k(:) l(:)]),2);
%use unique to identify duplicates
[f,g,h]=unique(ac,'rows');
%count
cnt=histc(h,1:max(h));
disp([h(g),k(g), l(g),z(g),cnt])
i just want to delete or terminate rows containing z>=90, i can't used break because it only works in for loop or while loop,
so what other command may i use? thankas.
0 个评论
回答(1 个)
Orion
2015-2-5
try something like this
% create a matrix with all vectors
M = [h(g),k(g), l(g),z(g),cnt];
% define the threshold for z
threshold = 0.90;
% delete all lines with z>0.90
M(M(:,4)>threshold,:) = [];
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!