How to delete rows in matlab

3 ビュー (過去 30 日間)
norscrown
norscrown 2015 年 2 月 5 日
コメント済み: norscrown 2015 年 2 月 5 日
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.

回答 (1 件)

Orion
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,:) = [];
  2 件のコメント
norscrown
norscrown 2015 年 2 月 5 日
i'm sorry but it doesn't display the output i want
norscrown
norscrown 2015 年 2 月 5 日
if true
% code this is the output i want
h k l z cnt
0 0 1 1 6
0 0 2 4 6
0 0 3 9 6
0 1 1 2 12
0 1 2 5 24
0 1 3 10 24
0 2 2 8 12
0 2 3 13 24
1 1 1 3 8
1 1 2 6 24
1 1 3 11 24
1 2 2 9 24
1 2 3 14 48
2 2 2 12 8

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

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by