フィルターのクリア

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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by