In a randomly generated matrix how to find the position(row and column) of an element by using its value?

1 visualizzazione (ultimi 30 giorni)
Ive created a 5x5 matrix using the rand() function
A=rand(5)
0.4427 0.8173 0.8001 0.1455 0.1450
0.1067 0.8687 0.4314 0.1361 0.8530
0.9619 0.0844 0.9106 0.8693 0.6221
0.0046 0.3998 0.1818 0.5797 0.3510
0.7749 0.2599 0.2638 0.5499 0.5132
B=find(a==0.0844)
after i enter the above code for finding the position of that particular element, the output becomes " 0x1 empty double column vector "
Im literally a newbie to matlab software so kindly help me

Risposta accettata

KSSV
KSSV il 27 Mag 2020
Your matrix has floating point numbers..you cannot get the value you want using like that. You should use:
tol = 10^-5 ; % tolerance
B = find(abs(A-0.0844)<tol)

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by