フィルターのクリア

Remove Entire Column when a condition is met.

2 ビュー (過去 30 日間)
Pragyan Dahal
Pragyan Dahal 2019 年 10 月 30 日
コメント済み: Pragyan Dahal 2019 年 10 月 30 日
Hello, I am constructing a cost matrix for an association problem. It is a minimization problem and the cost matrix is structured in this way
C=[12 inf 13 inf inf inf inf;
13 inf 15 inf inf inf inf;
inf inf inf 14 inf 27 inf]
The aim for me is to remove the column in which I have inf elements only i.e. in this example i want to remove 2nd, 5th and 7th column from the cost matrix.
Thanks in advance for the help.

回答 (1 件)

pavan kumar
pavan kumar 2019 年 10 月 30 日
C(:,2)=[]
C(:,4)=[]
C(:,5)=[]
  2 件のコメント
Pragyan Dahal
Pragyan Dahal 2019 年 10 月 30 日
Thank you very much for the reply, this i figured given some answers for the row cases in this forum, but i am not sure on how to define the condition here, i mean, condition such that all the elements are infinite....
Pragyan Dahal
Pragyan Dahal 2019 年 10 月 30 日
I was able to solve the issue by using the code segment shown below.
remove=true(size(C,2),1);
for pp=1:size(C,2)
qq=1;
while C(qq,pp)==inf
qq=qq+1;
if qq==size(C,1)+1
remove(pp)=0;
break
end
end
end
C=C(:,remove)

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by