Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Array Problem

Subject: Array Problem

From: donny jason

Date: 28 Oct, 2011 14:27:11

Message: 1 of 9

Hello there,

I would like ask how can I store total number of each row into an array?
For example, A = [1 3 5;2 4 6;7 9 11];
total number of row 1 = 9, row 2 = 12, row 3 = 27,
how to store it in an array 3 by 1?

Subject: Array Problem

From: ade77

Date: 28 Oct, 2011 14:44:15

Message: 2 of 9

"donny jason" wrote in message <j8ee3u$sdp$1@newscl01ah.mathworks.com>...
> Hello there,
>
> I would like ask how can I store total number of each row into an array?
> For example, A = [1 3 5;2 4 6;7 9 11];
> total number of row 1 = 9, row 2 = 12, row 3 = 27,
> how to store it in an array 3 by 1?

row = sum(A,2)

Subject: Array Problem

From: donny jason

Date: 28 Oct, 2011 14:57:12

Message: 3 of 9

> row = sum(A,2)

Thank you for the reply.
By the way, how can we differentiate it is which row if the matrix is large?

Subject: Array Problem

From: Ataías Pereira Reis

Date: 28 Oct, 2011 15:18:40

Message: 4 of 9

I think you could save it in a variable and then access the value of the row or rows you want.

kind of:
A = [1 3 5
     2 4 6
     7 9 11];
row = sum(A,2);
row(1) - first row sum
row(2) - second row sum
row(3) ... row(n)

Subject: Array Problem

From: donny jason

Date: 28 Oct, 2011 15:42:27

Message: 5 of 9

> A = [1 3 5
> 2 4 6
> 7 9 11];
> row = sum(A,2);
> row(1) - first row sum
> row(2) - second row sum
> row(3) ... row(n)

Thank you for the reply. Finally i got it. But how do we find it if i use this way,
[R C] = size(A);
for i=1:1:R,
row=0;
for j=1:1:C,
row = row+X(i,j);
end
end

Subject: Array Problem

From: donny jason

Date: 28 Oct, 2011 15:59:15

Message: 6 of 9

i got it already.thank you for all the comment.

Subject: Array Problem

From: donny jason

Date: 29 Oct, 2011 10:08:14

Message: 7 of 9

Does anyone know how can I find which is the row of the maximum number found?

Subject: Array Problem

From: dpb

Date: 29 Oct, 2011 13:42:15

Message: 8 of 9

On 10/29/2011 5:08 AM, donny jason wrote:
> Does anyone know how can I find which is the row of the maximum number
> found?

yes... :)

--

Subject: Array Problem

From: dpb

Date: 29 Oct, 2011 17:30:26

Message: 9 of 9

On 10/29/2011 8:42 AM, dpb wrote:
> On 10/29/2011 5:08 AM, donny jason wrote:
>> Does anyone know how can I find which is the row of the maximum number
>> found?
>
> yes... :)
>

OK, the question I presume you _meant_ to ask but didn't... :)

The Matlab way would be to use the optional index return values of the
max() function.

If you're still wanting the non-Matlab solution in Matlab, the hint is
to save an initial value for the index in a variable then make a logical
test and update that value for the suitable conditions. The precise
details are left as an "exercise for the student" (at least until you
post your work... :) )

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us