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: substitute selected array element values with those from other array
Replies: 3   Last Post: Jun 3, 2011 3:31 PM

Advanced Search

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

Posts: 87
Registered: 12/17/10
Re: substitute selected array element values with those from other array
Posted: Jun 3, 2011 10:37 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Steve,

Thanks, these steps put me closer, however LNOx_vert_land(mask) is a 25180 x 1 array.
I want to replace those 25180 elements from LNOx_vert_land to LNOx_vert_ocean.

Jonathan

"Steven_Lord" <slord@mathworks.com> wrote in message <isaphe$plf$1@newscl01ah.mathworks.com>...
>
>
> "Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
> news:is9058$3ar$1@newscl01ah.mathworks.com...

> > I have 2 arrays:
> >
> > LNOx_vert_ocean = bsxfun(@times, apply_250_km2, lnox_mass_frac_ocean);
> > LNOx_vert_land = bsxfun(@times,apply_250_km2, lnox_mass_frac_land);
> > Both will have the size 332 x 165 x 27 x 3.
> >
> > I want to substitute SOME (not all) elements in LNOx_vert_ocean with some
> > elements in LNOx_vert_land.
> >
> > The substitution will be based off of a 3rd array LU (land use). This
> > array is 332 x 165. If the value of the elements in LU is not equal 16
> > then that is land. Those are the values to be substituted into
> > LNOx_vert_ocean.
> >
> > Amongst several things I have tried the following which did not work:
> > LNOx_vert = LNOx_vert_ocean(LNOx_vert_land(LU ~= 16));

>
> No, that won't. Work your way outward to describe what that line is doing.
>
> 1) (LU ~= 16) creates a logical array with 1 where the corresponding element
> of LU is not equal to 16 and 0 where it is.
> 2) LNOx_vert_land(step 1) returns those elements of LNOx_vert_land where the
> corresponding elements of LU are not equal to 16.
> 3) LNOx_vert_ocean(step 2) returns those elements of LNOx_vert_ocean where
> the corresponding elements of LNOx_vert_land correspdong to elements of LU
> that are not equal to 16. That's not what you're looking for, is it?
>
>
> Instead, use step 1 as a mask into each of LNOx_vert_ocean and
> LNOx_vert_land separately.
>
> mask = (LU ~= 16);
> LNOx_vert_ocean(mask) = LNOx_vert_land(mask);
>
> That replaces those elements in LNOx_vert_ocean that correspond to non-16
> elements in LU with the elements in LNOx_vert_land that correspond to non-16
> elements in LU -- or to put it another way, it replaces those elements in
> LNOx_vert_ocean that correspond to land with the elements of LNOx_vert_land
> that correspond to land. Does that description match what you want to do?
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com




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.