Matrix of numbers problem

2 Ansichten (letzte 30 Tage)
Kristian
Kristian am 12 Mär. 2012
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 Kommentar
Kristian
Kristian am 12 Mär. 2012
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

G A
G A am 12 Mär. 2012
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 Kommentar
Kristian
Kristian am 12 Mär. 2012
Please see my comment above. does that clarify?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by