keeping elements with specific conditions in a matrix
古いコメントを表示
Hello,
In matrix A, I need the first value of each column which is not 999. If in any column all values are 999, then I take 999. I want to avoid loops. Matrix A can have different sizes. So, I am looking for B here
A=[.1 999 999 999;
.3 .8 999 999;
.1 .2 .3 999]
B=[.1 .8 .3 999]
1 件のコメント
Azzi Abdelmalek
2012 年 9 月 17 日
編集済み: Azzi Abdelmalek
2012 年 9 月 17 日
FATEMEH, have you tried my code?
採用された回答
その他の回答 (1 件)
Azzi Abdelmalek
2012 年 9 月 14 日
編集済み: Azzi Abdelmalek
2012 年 9 月 14 日
B=~(A==999)
res=[];
for k=1:size(B,2);
res=[res ;A(max([1 ;find(B(:,k)==1,1)]),k)];
end
res=res'
2 件のコメント
FATEMEH
2012 年 9 月 17 日
Azzi Abdelmalek
2012 年 9 月 17 日
ok try this
B=~(A==999);
[n,m]=size(B);
q =mat2cell(B,n,ones(1,m))
idx=cell2mat(cellfun(@(x) max([1 find(x,1,'first')]),q ,'uni',false))
B=A(idx+(0:m-1)*n)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!