フィルターのクリア

How to delete elements from vector in for loop?

15 ビュー (過去 30 日間)
Murat Yetkin
Murat Yetkin 2017 年 9 月 8 日
コメント済み: Image Analyst 2017 年 9 月 8 日
I have an A vector and I want to remove values less than the 0.1*max(A). Also I want to remove same rows in a B vector with respect to A:
size(B)= 801 1 size(A)=801 1
The error that I got is:
'A null assignment can have only one non-colon index.'
for p=length(A):-1:1
if A(p,1)<max(A)*0.1
A(p,1)=[]; B(p,1)=[];
end
end

採用された回答

Image Analyst
Image Analyst 2017 年 9 月 8 日
Try this:
rowsToDelete = 0.1*max(A);
A(rowsToDelete) = [];
B(rowsToDelete) = [];
No loop needed.
The problem was that it was considering the array as a 2-D array because you included the ",1" in the indexing. And you can't delete just one element from a 2-D array because you can't have arrays with ragged edges. You have to delete a whole column or a whole row, not part of a row or column.
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2017 年 9 月 8 日
編集済み: Andrei Bobrov 2017 年 9 月 8 日
rowsToDelete = A < 0.1*max(A);
A(rowsToDelete) = [];
B(rowsToDelete) = [];
Image Analyst
Image Analyst 2017 年 9 月 8 日
Thanks for the correction Andrei!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange루프와 조건문 についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!