How to locate a decimal in a matrix?

조회 수: 3 (최근 30일)
Jose Grimaldo
Jose Grimaldo 2019년 10월 19일
답변: Star Strider 2019년 10월 19일
How would i locate a decimal value inside a square matrix?
For example x=[1 2.5 3;5 7 1;2 6 4.2]
Would i used functions like mod and find?
  댓글 수: 1
James Tursa
James Tursa 2019년 10월 19일
A specific decimal? Any non-integer value?

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

채택된 답변

Star Strider
Star Strider 2019년 10월 19일
It depends on what you want. If you want the indices, use both. If you want the values, just rem (or mod) will work.
Try this:
x=[1 2.5 3;5 7 1;2 6 4.2];
Lm = rem(x, 1) ~= 0
Out = x(Lm)
producing:
Out =
2.5
4.2
To locate their row and column indices:
[r,c] = find(Lm)
produces:
r =
1
3
c =
2
3
Experiment to get the result you want.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by