필터 지우기
필터 지우기

How to use for loop compare all values in a 2x2 matrix?

조회 수: 2 (최근 30일)
Yuan Yuan Lin
Yuan Yuan Lin 2020년 10월 29일
댓글: Yuan Yuan Lin 2020년 10월 29일
Hi.
I'm a beginner and I'm just starting to learn Matlab so I'm not very familiar with the code syntax right now. But I'm working on the following problem.
A = [1, 2; 4, 6]
How do you use for loop to compare all the values in A to see which ones are greater than 3 and have those added together to make D?
Thanks.

채택된 답변

KSSV
KSSV 2020년 10월 29일
It is your home work...so you have to do it yourself. Follow the below hints.
  1. You can get the dimensions/ size of a matrix using size.
  2. You can comapre the elements using inequalitties >, <. >=, <=.
  3. Also you can use logical indices striaght away with out loop.
  4. To add you have to use +.
  댓글 수: 5
KSSV
KSSV 2020년 10월 29일
You can try what A(:) prints, in command window instead of asking a question. This will help ypu to understand yourself. Anything, you have a doubts just type in command window and see it. You can get yourself.
A(:) this will make a matrix into a single column vector.
idx gives logical indices whose values are >3.
Yuan Yuan Lin
Yuan Yuan Lin 2020년 10월 29일
Okay. I'll try it on my own. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by