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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by