if i have matrix and i want to do this ?

2 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2016-5-3
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
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

请先登录,再进行评论。

采纳的回答

Stalin Samuel
Stalin Samuel 2016-5-3
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by