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: insert vector in a 4D array
Replies: 4   Last Post: Jun 26, 2011 7:04 AM

Advanced Search

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

Posts: 69
Registered: 12/7/04
Re: insert vector in a 4D array
Posted: Jun 26, 2011 6:50 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Thanks for proposing this solution but I was thinking more of a durect substitution
for replacing the first line in each array for all dimensions, something like

A(1.:.:.:)=V which does not work

"Nasser M. Abbasi" <> wrote in message <iu6cnn$qa6$>...
> On 6/25/2011 8:25 PM, Nasser M. Abbasi wrote:
> > On 6/25/2011 6:31 PM, Michel wrote:
> >> I have a 4D array size [367 41 25 15] and would like to insert the vector [1961:2001] in
> >> the first line of the first dimension.
> >> How can I do it?
> >> Thanks

> >
> >
> > If A was the 4D array, and v is the above vector, then try
> >
> > A(1,:,1,1)=v
> >
> > --Nasser

> btw, I understood what you wanted is to replace only the first row
> in first matrix by v.
> If you meant to replace EACH first row in each matrix in each higher
> dimension, then may be double loop might be an easy way to do it
> otherwise you have to do reshape and such and put things back.
> But I think loop is easier in this case:
> ---------------------------------
> A=rand(367,41,25,15);
> third_diemension=25;
> fourth_diemension=15;
> v=1961:2001;
> for i=1:third_diemension
> for j=1:fourth_diemension
> A(1,:,i,j)=v;
> end
> end
> ---------------------------
> You can interchange the order of the 'j', 'i' above to see
> if you might get a difference in performance. But for such
> small matrix size (45 MB?), it should not matter.
> May be an expert will show us a shorter or better way.
> --Nasser

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.