Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 5월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
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 ))

답변 (1개)

Image Analyst
Image Analyst 2016년 5월 2일
편집: Image Analyst 2016년 5월 2일
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
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 5월 2일
how can i show the result ?
Image Analyst
Image Analyst 2016년 5월 2일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by