How to do a simple elementwise logic in a matrix?

Let's say I have A=[1 0.5 2; 0.5 1 1; 3 1 0.5];
I need to create a new matrix (with the same size as A) in which elements of A that are less than one are multiplied by 10 and those elements larger than one are multiplied by 100. I know how to do it with a 'for', but any better idea?
Thanks,

댓글 수: 2

Sounds like homework. What have you tried?
MJ
MJ 2013년 12월 19일
lol, it's not actually! I'm using this:
z1=(A<=1).*(A.*10)
z2=(A>1).*(A.*200)
then I don't know how to merge z1 and z2 together! I guess there should be a simpler way...

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2013년 12월 19일

0 개 추천

You're so close!
(A<=1).*(A.*10) + (A>1).*(A.*100)
(You wrote 100 in your question, but used 200 in your code.)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

태그

질문:

MJ
2013년 12월 19일

답변:

2013년 12월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by