apply condition on Matrix?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali Mukhtar
am 9 Sep. 2019
Kommentiert: Ali Mukhtar
am 9 Sep. 2019
if i have a matrix B=[1111000] and another integer T=4 i want to apply while loop if number of One's in B>=T how should i write it to get desire condition
12 Kommentare
Akzeptierte Antwort
madhan ravi
am 9 Sep. 2019
Bearbeitet: madhan ravi
am 9 Sep. 2019
Just use logical indexing "==" to see the values equal 1 and use nnz() and then use >= T if you get 1 it's true else false.
help ==
help nnz
help >=
Weitere Antworten (1)
David Hill
am 9 Sep. 2019
If B is a 1 by x vector of 1's and 0's (B = [1,1,1,1,1,0,0,0,0,0])
while sum(B)>T
if B is a 1 by x character array (B = '1111100000')
while sum(double(B)-48)>T
Your matrix B is not described well above, it looks like a single number.
3 Kommentare
David Hill
am 9 Sep. 2019
If your array is a character array '111110000', then I converted to a number array which is a ascii representative of each character and subtract 48=='0' to get an array of 1's and 0's. If you already have an array of 1's and 0's you don't need to do this.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!