The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: sum matrix element in different array
Replies: 2   Last Post: Jan 3, 2013 1:59 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 25
Registered: 11/26/12
sum matrix element in different array
Posted: Jan 3, 2013 7:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear All,

I would appreciate some help on this one please.

I am summing matrix elements in different arrays. Say we have 2 arrays:


Price is a cell composed of different matrices. The same for Coupon.

Now the size of the matrices inside "Price" and "Coupon" are not always equal. Of course if I run a code similar to this...

for i=1:10

Price{1,i}+ coupon{1,i};


...I get an error which what you would expect because the first matrix of "Price" and "Coupon" are of different size, ....

Now I would like to run an If statement to say: if matrix sizes of Price and Coupon are similar then sum them, if they are not equal then drop that extra elements (at the end) and just sum the first elements. How can I do that please?

example to illustrate:
size(Price{1,1})=size(Coupon{1,1})= (1000,1)
size(Price{1,2})=(995,1) < size(Coupon{1,2})= (1000,1)

I would like to ignore the extra elements (at the end) of Coupon{1,2} and then sum the remaining elements (i.e. from 1:995) with Price{1,2}? How Can I do that please?

Thanks a lot

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.