Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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 ]
dpb

Posts: 8,288
Registered: 6/7/07
Re: sum matrix element in different array
Posted: Jan 3, 2013 8:07 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 1/3/2013 6:24 AM, Saad wrote:
> 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=num2cell(1:10);
> Coupon=num2cell(1:10);
>
> 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};
> end
> ...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?
>

...

nmin=min(length(x),length(y));
s=x(1:nmin)+y(1:nmin);

Salt to suit...

--




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.