How total of column of a matrix can be kept be same????

조회 수: 2 (최근 30일)
suchismita
suchismita 2014년 6월 12일
댓글: suchismita 2014년 6월 12일
If I have a matrix A A=[ 0.4000 0.6000 0.8000 0.8000 1.0000 1.6000 0.9333 1.2333 0.0000 0.0000; 1.2000 0.6000 0.8000 0.8000 1.0000 0.4000 0.5333 0 0 0; 1.2000 1.4000 1.6000 1.6000 1.8000 2.4000 2.5333 2.8333 4.0000 4.0000; 1.2000 1.4000 0.8000 0.8000 0.2000 0 0 0 0 0] I want to keep the total of column to remain same as here the total of each column is as:
sum(A(:,1))
ans =
4
>> sum(A(:,2))
ans =
4
>> sum(A(:,3))
ans =
4
>> sum(A(:,4))
ans =
4
>> sum(A(:,5))
ans =
4
>> sum(A(:,6))
ans =
4.4000
>> sum(A(:,7))
ans =
4
>> sum(A(:,8))
ans =
4.0667
>> sum(A(:,9))
ans =
4
>> sum(A(:,10))
ans =
4
at 6th and 8th column its becoming more than 4 .... so here how can round of this to 4??? plz plz help.....
  댓글 수: 3
suchismita
suchismita 2014년 6월 12일
yes....if needed some should be deleted to get 4
suchismita
suchismita 2014년 6월 12일
here in my example matrix can you help me in modifying without disturbing the zeros...please...like if in a column sum is more than 4 it should minus the rest and if its less it should add to make it 4... can you help me in that way...

댓글을 달려면 로그인하십시오.

채택된 답변

Jos (10584)
Jos (10584) 2014년 6월 12일
This is called a normalisation procedure.
A = rand(10,6) % some random data
sumA = sum(A,1) % unequal column sums
normfun = @(a,b) 4 * (a/b)
Anorm = bsxfun(normfun, A, sumA) % normalise each column
sum(Anorm,1) % all 4, check!
  댓글 수: 1
suchismita
suchismita 2014년 6월 12일
thank u so much... but here in my example matrix can you help me in modifying without disturbing the zeros...please...like if in a column sum is more than 4 it should minus the rest and if its less it should add to make it 4... can you help me in that way...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by