Matrix operations

i have an n by i matrix call it B. I want to apply two different operations to B. I want to perform the first operation on elements of B<0 and then perform the other operation to the rest of B. The operations themselves are n by n matrices. How do i do it please?

답변 (1개)

Titus Edelhofer
Titus Edelhofer 2011년 7월 25일

0 개 추천

Hi,
use logical indexing:
idx = B<0;
% operate on these indices:
B(idx) = ...;
% and now on those >= 0:
B(~idx) = ...;
Titus

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

2011년 7월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by