identifying entry elements in rows of logical matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
julian gaviria
il 25 Gen 2023
Commentato: Dyuman Joshi
il 27 Gen 2023
I want to identifiy the entry elements (i.e., the first "1" value) in the rows of the following logical matrix
input_matrix = [1 1 1; 0 1 1; 0 0 0; 0 1 0];
the expected matrix would be the following:
output_matrix = [1 0 0; 0 1 0; 0 0 0; 0 1 0];
The position of the "entries" (first "1" values) in both input and output matrices is respected. Also, Further "1" values (following the entries) have been replaced with "0" values.
Thanks in advance for any hint.
2 Commenti
Dyuman Joshi
il 26 Gen 2023
Modificato: Dyuman Joshi
il 26 Gen 2023
@julian gaviria Just a note -
My and Stephen's code did exactly what was asked.
You should have clarified what exactly you wanted, in your question statement. The comments on my code clearly indicated what the code does, and you should have picked up from them that it is not what you want to do and mentioned it in reply to that.
I will be deleting my solution.
Risposta accettata
Più risposte (1)
Fangjun Jiang
il 25 Gen 2023
in = [1 1 1; 0 1 1; 0 0 0; 0 1 0];
M=size(in,1);
temp=[zeros(M,1), in];
d=diff(temp,1,2);
out=(d==1)
3 Commenti
Dyuman Joshi
il 25 Gen 2023
This wouldn't work if there is a 1 after a 0
in = [1 1 0 1; 0 1 1 1; 0 0 0 0; 0 0 1 0];
M=size(in,1);
temp=[zeros(M,1), in];
d=diff(temp,1,2);
out=(d==1)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!