Adding all the rows of a matrix

1 vue (au cours des 30 derniers jours)
Khadija Khan
Khadija Khan le 11 Avr 2018
I have a matrix A=[1 0 3 0 0; 0 1 0 1 0]; I have B=sum(A); B=[1 1 3 1 0]; After performing some operation on this matrix B let my matrix B is B=[0.1 0.1 0.25 0.1 0], How can I get back A=[0.1 0 0.25 0 0; 0 0.1 0 0.1 0]. Note: This operation can only be performed on Matrix B. Can anybody help? Thanks in advance
  3 commentaires
Rik
Rik le 11 Avr 2018
Have you seen what you posted? It is unreadable. Select the code you have in your comment and click the {}Code button.
And if you have working code, what is your question?
Khadija Khan
Khadija Khan le 11 Avr 2018
Modifié(e) : Khadija Khan le 11 Avr 2018
I solved it Thank you so much Rik Wisselink
Q=20;
Kr=2;
Kt=3;
A=[10 0 0 ; 0 22 0];
B=sum(A);
if (sum(B(1,:)) > Q)
sorted_matrix = sort(B(1,:),'descend');
N_tilde = size(sorted_matrix,2);
sorted_matrix(end+1) = -Inf;
while(N_tilde > 0)
if ((sorted_matrix(N_tilde) > sorted_matrix(N_tilde+1)) && ...
(sorted_matrix(N_tilde) > (sum(sorted_matrix(1:N_tilde))-Q)/N_tilde))
mu = (sum(sorted_matrix(1:N_tilde))-Q)/N_tilde;
B(1,:) = max(B(1,:) - mu, 0);
break;
else
N_tilde = N_tilde - 1;
end
end
end
A_temp=zeros(Kr,Kt);
for row=1:Kr
for col=1:Kt
if A(row,col)>0
A_temp(row,col)=1;
else
A_temp(row,col)=A(row,col);
end
end
end
A_final=zeros(Kr,Kt);
for r=1:Kr
A_final(r,:)=A_temp(r,:).*B;
end

Connectez-vous pour commenter.

Réponses (1)

Khadija Khan
Khadija Khan le 11 Avr 2018
Rik Wisselink when I asked the Question, I was struggling with the code. Now it's working fine. Thanks

Catégories

En savoir plus sur Matrix Indexing 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