Matrix of numbers problem

조회 수: 1 (최근 30일)
Kristian
Kristian 2012년 3월 12일
hi,
I have a little challenge that I can't figure out how to code in matlab
The problem is quite simple and I can do it by hand for small matrices
Example with a 6x3 matrix:
1 3 5
2 6 4
3 1 6
4 5 2
5 4 1
6 2 3
The sum of first and second row must be equal to the sum of every column. same goes for the sum of row three and four and so on! So for the 6x3 matrix above: the sum of row 1 and 2 is 21, the sume of row 3 and 4 is 21 and the sum of row 5 and 6 is 21.. Also the sum of each column must individually be 21..
I'm doing this for a small hobby project and for about 1000 rows and 500 columns, so I figured Matlab is the way to go.
Any help is very much appreciated!
  댓글 수: 1
Kristian
Kristian 2012년 3월 12일
I'm thinking something like (matrix named A)
n=6 %(number of rows)
for j=1..n/2
R(i)=sum(A(2*i-1,:))+sum(A(2*i,:))
C(i)=sum(A(:,i))
end
now what im missing is a function/command that lets Matlab fill matrix A with integers from 1...n and add the condition that
R(i)=C(i) for all i
any help?

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

답변 (1개)

G A
G A 2012년 3월 12일
a.*ones(1000,500)
Where a is any number. Sum of each pair of rows and sum of each column is equal to a*1000. That means that we need more specific statement of problem.
  댓글 수: 1
Kristian
Kristian 2012년 3월 12일
Please see my comment above. does that clarify?

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

카테고리

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