Info
この質問は閉じられています。 編集または回答するには再度開いてください。
i want to generate a random matrix then apply this condition ?
1 回表示 (過去 30 日間)
古いコメントを表示
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 ))
0 件のコメント
回答 (1 件)
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 件のコメント
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!