Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

i want to generate a random matrix then apply this condition ?

1 Ansicht (letzte 30 Tage)
Firas Al-Kharabsheh
Firas Al-Kharabsheh am 2 Mai 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
i want a for statement to compute this after generate a (n,m) random matrix
  • compute number of ones in each group of ones in each row and put it in A_rows 'size = (n,m/2)'
  • compute number of ones in each group of ones in each column and put it in A_column 'size = (n/2,m) '
A = [ 1 1 0 1 0 1
0 1 1 0 0 1
0 0 1 0 1 0
1 1 0 1 1 0
1 1 1 0 1 1 ]
A_row = [ 2 1 1
2 1 0
1 1 0
2 2 0
3 2 0 ]
A_column = [ 0 0 0 0 0 0
1 2 2 1 0 2
2 2 1 1 3 1 ]
after that compute number of ones and put it in A_sum_row and how element in each row in A_row non zero and put it in A_num_row
A_sum = [ 4
3
2
4
5 ]
A_num_row = [ 3
2
2
2
2]
after that i want to check if A_sum_row + A_num_row -1 == m
if this condition true then GENERATE F zeros and go to A_row in the same row and put the number of ones like the number in the A_row
F_row = [ 1 1 0 1 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1 1 1 0 1 1 ]
finally do the same thing for A_column where the final result for the column will be
F_column = [ 0 1 0 0 0 0
0 1 0 0 0 0
0 0 0 0 0 0
0 1 0 0 0 0
0 1 0 0 0 0 ]
  • i need it using (( For statement ))

Antworten (1)

Image Analyst
Image Analyst am 2 Mai 2016
Bearbeitet: Image Analyst am 2 Mai 2016
I'm assuming this is homework so I'll just give hints. To do the first two you can use bwlabel and regionprops(). Those will give you the number of 1 groups and the number of 1's in each of the groups. Do a loop over rows, extracting each row and doing bwlabel and regionprops on each row.
For the second part, you can use the sum() function like you did.
I've removed the tag coder because this has nothing to do with the Coder product that converts MATLAB code to C code, and I've removed the useless tags code and matlab. You don't need to use them since all questions here are on matlab code.
  4 Kommentare
Image Analyst
Image Analyst am 2 Mai 2016
You can just put the name of the variable all by itself on a line without the semicolon and it will print the value to the command window.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by