if i have matrix and i want to do this ?

2 views (last 30 days)
if i have this matrix
Matrix_row = [2 4 2 0 0
3 6 0 0 0
4 5 0 0 0
1 2 2 0 0
1 2 1 1 0
1 2 2 0 0
2 3 2 0 0
2 2 2 0 0
1 1 1 4 0
10 0 0 0 0 ]
and i compute this values
a = [ 8
9
9
5
5
5
7
6
7
10 ]
and b = [ 3
2
2
3
4
3
3
3
4
1 ]
i need to chick like this
f = zeros(10,10)
for k=1:10
if a(k) + b(k)-1 == 10 if this condition true then
go bake to Matrix_row(k) and convert this row to be a binary
(the number in Matrix_row shows how many number of ones in this row like
[2 4 2] == [1 1 0 1 1 1 1 0 1 1]
  • when the condition is true , the number in Matrix_row in that row must between the group of ones just one zero
the final solution will be
F = [ 1 1 0 1 1 1 1 0 1 1
1 1 1 0 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1 1 ]
  2 Comments
Image Analyst
Image Analyst on 3 May 2016
Is this your homework?
The badly-named "a" looks like sum(M, 2). But how did you compute the (also badly-named) "b"?
Firas Al-Kharabsheh
Firas Al-Kharabsheh on 3 May 2016
No its not a homework , its a part from a graduation project in computer science ,
a=sum(Matrix_row,2)
b=sum(Matrix_row~=0,2)
can you help me to solve to generate F like the final solution

Sign in to comment.

Accepted Answer

Stalin Samuel
Stalin Samuel on 3 May 2016
clear all
clc
Matrix_row = [2 4 2 0 0
3 6 0 0 0
4 5 0 0 0
1 2 2 0 0
1 2 1 1 0
1 2 2 0 0
2 3 2 0 0
2 2 2 0 0
1 1 1 4 0
10 0 0 0 0 ]
a = [ 8
9
9
5
5
5
7
6
7
10 ]
b = [ 3
2
2
3
4
3
3
3
4
1 ]
f = zeros(10,10)
for k=1:10
tmp = Matrix_row(k,:)
tmp(tmp==0) = [];
if a(k) + b(k)-1 == 10
n1 = 1
for s=1:length(tmp)
f(k,n1:n1+tmp(s))=1;
f(k,n1+tmp(s))=0;
n1 = n1+tmp(s)+1;
end
end
end
f(:,11)=[];
disp(f)

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!