Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

removing cells that satisfy a specific condtion

조회 수: 1 (최근 30일)
Christos
Christos 2013년 1월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello everyone. I have a cell array, from which the cells contain a matrix. I want to remove the cells for which, lets say inv(cell{i}'*cell{i}) gives a warning message that matrix is almost singular. is there a way to do this? I would really appreciate if someone knows how to do this

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 15일
편집: Azzi Abdelmalek 2013년 1월 15일
for k=1:numel(A) % A is you cell array
try
a=inv(A{k}'*A{k})
out{k}=A{k} % out is the result
catch err
end
end
  댓글 수: 5
Brian B
Brian B 2013년 1월 15일
You could also use Azzi's code if you force the warning you expect to be handled like an error, as discussed at http://undocumentedmatlab.com/blog/trapping-warnings-efficiently/.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 15일
편집: Azzi Abdelmalek 2013년 1월 15일
look at this example
A={[1 2 3 0 0 0; 0 0 0 0 0 0], randi(16,4)}
l=0;
for k=1:numel(A) % A is you cell array
try
a=inv(A{k})
l=l+1
out{l}=A{k} % out is the result
catch err
end
end
out
% the first matrix is not square, can't be reversed, then it will not apear in out array.
% I am not sure if the message "matrix is almost singular" is considered as an error mesage

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by