Search All of the Math Forum:

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

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

 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

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" <nma@12000.org> wrote in message <iu6cnn\$qa6\$1@speranza.aioe.org>...
> 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

Date Subject Author
6/25/11 Michel Slivitzky
6/25/11 Nasser Abbasi
6/26/11 Nasser Abbasi
6/26/11 Michel Slivitzky
6/26/11 Nasser Abbasi