Filter löschen
Filter löschen

counting the number of 1's and 0's in each row

3 Ansichten (letzte 30 Tage)
Panda Girl
Panda Girl am 16 Nov. 2018
Kommentiert: Panda Girl am 16 Nov. 2018
  • >> tag123_data = [0;1;1]
  • tag123_data =
  • 0
  • 1
  • 1
  • >> scm = randi(0:1,3,16)
  • scm =
  • 1 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1
  • 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1
  • 0 0 1 0 1 1 0 0 1 0 0 1 1 1 1 0
  • >> out_data = xor(tag123_data,scm)
  • out_data =
  • 3×16 logical array
  • 1 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1
  • 0 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0
  • 1 1 0 1 0 0 1 1 0 1 1 0 0 0 0 1
How do i count the number of 1's and 0's in in each row?? Like in row 1 there are 11 1's and 5 0's and in row 2 there are 9 1's and 7 0's how to write a syntax showing the count of 1's and 0's in every row

Akzeptierte Antwort

Miriam
Miriam am 16 Nov. 2018
tag123_data = [0;1;1];
scm = randi(0:1,3,16);
out_data = xor(tag123_data,scm);
n_ones = sum(out_data,2);
n_zeros = size(out_data,2) - n_ones;
  1 Kommentar
Panda Girl
Panda Girl am 16 Nov. 2018
Thank you so much for your reply. This works, really appreciate your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by