if i have matrix and i want to do this ?

2 vues (au cours des 30 derniers jours)
Firas Al-Kharabsheh
Firas Al-Kharabsheh le 3 Mai 2016
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 commentaires
Image Analyst
Image Analyst le 3 Mai 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 le 3 Mai 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

Connectez-vous pour commenter.

Réponse acceptée

Stalin Samuel
Stalin Samuel le 3 Mai 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)

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by