Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Did ndgrid change?

Subject: Did ndgrid change?

From: Greg von Winckel

Date: 12 Dec, 2007 10:14:35

Message: 1 of 6

I had this bit of code which used to work in a previous
version of MATLAB but no longer functions in the current
version

for k=1:n
    [q{k},w{k}]=rquad(N,k-1);
end

[Q{1:n}]=ndgrid(q{:}); [W{1:n}]=ndgrid(w{:});

clear q w; q=zeros(Nn,n); w=q; X=q;

for k=1:n
    q(:,k)=reshape(Q{k},Nn,1); w(:,k)=reshape(W{k},Nn,1);
end

map=eye(m); map(2:m,1)=-1; c=map*vert;
W=abs(det(c(2:m,:)))*prod(w,2);

for k=1:n-1
    X(:,k)=(1-q(:,k)).*prod(q(:,1:k-1));
end

which now gives the error

??? Error using ==> times
Matrix dimensions must agree.

Error in ==> nsimplexquad at 37
    X(:,k)=(1-q(:,k)).*prod(q(:,1:k-1));


It seems that now ndgrid only returns the first argument. Is
there a workaround?

Thanks,
Greg

Subject: Did ndgrid change?

From: Jos

Date: 12 Dec, 2007 11:37:49

Message: 2 of 6

"Greg von Winckel" <gregvw@gmail.com> wrote in message
<fjocab$nqi$1@fred.mathworks.com>...
> I had this bit of code which used to work in a previous
> version of MATLAB but no longer functions in the current
> version
>
> for k=1:n
> [q{k},w{k}]=rquad(N,k-1);
> end
>
> [Q{1:n}]=ndgrid(q{:}); [W{1:n}]=ndgrid(w{:});
>
> clear q w; q=zeros(Nn,n); w=q; X=q;
>
> for k=1:n
> q(:,k)=reshape(Q{k},Nn,1); w(:,k)=reshape(W{k},Nn,1);
> end
>
> map=eye(m); map(2:m,1)=-1; c=map*vert;
> W=abs(det(c(2:m,:)))*prod(w,2);
>
> for k=1:n-1
> X(:,k)=(1-q(:,k)).*prod(q(:,1:k-1));
> end
>
> which now gives the error
>
> ??? Error using ==> times
> Matrix dimensions must agree.
>
> Error in ==> nsimplexquad at 37
> X(:,k)=(1-q(:,k)).*prod(q(:,1:k-1));
>
>
> It seems that now ndgrid only returns the first argument. Is
> there a workaround?
>
> Thanks,
> Greg
>

I am not sure, but could it be that

[C{1:n}] = ndgrid(q{:})

is interpreted (wrongly) as

[C{1:n}] = deal(ndgrid(q{:}))

??

Jos

Subject: Did ndgrid change?

From: John D'Errico

Date: 12 Dec, 2007 12:04:21

Message: 3 of 6

"Greg von Winckel" <gregvw@gmail.com> wrote in message
<fjocab$nqi$1@fred.mathworks.com>...
> I had this bit of code which used to work in a previous
> version of MATLAB but no longer functions in the current
> version
>
> for k=1:n
> [q{k},w{k}]=rquad(N,k-1);
> end
>
> [Q{1:n}]=ndgrid(q{:}); [W{1:n}]=ndgrid(w{:});

(snip)

> It seems that now ndgrid only returns the first argument. Is
> there a workaround?

This works for me in R2007a.

w = {1:2, 1:3, 1:4};
n = 3;

[W{1:n}]=ndgrid(w{:})
W =
    [2x3x4 double] [2x3x4 double] [2x3x4 double]

John

Subject: Did ndgrid change?

From: John D'Errico

Date: 12 Dec, 2007 12:04:44

Message: 4 of 6

"Greg von Winckel" <gregvw@gmail.com> wrote in message
<fjocab$nqi$1@fred.mathworks.com>...
> I had this bit of code which used to work in a previous
> version of MATLAB but no longer functions in the current
> version
>
> for k=1:n
> [q{k},w{k}]=rquad(N,k-1);
> end
>
> [Q{1:n}]=ndgrid(q{:}); [W{1:n}]=ndgrid(w{:});

(snip)

> It seems that now ndgrid only returns the first argument. Is
> there a workaround?

This works for me in R2007a.

w = {1:2, 1:3, 1:4};
n = 3;

[W{1:n}]=ndgrid(w{:})
W =
    [2x3x4 double] [2x3x4 double] [2x3x4 double]

John

Subject: Did ndgrid change?

From: John D'Errico

Date: 12 Dec, 2007 12:04:50

Message: 5 of 6

"Greg von Winckel" <gregvw@gmail.com> wrote in message
<fjocab$nqi$1@fred.mathworks.com>...
> I had this bit of code which used to work in a previous
> version of MATLAB but no longer functions in the current
> version
>
> for k=1:n
> [q{k},w{k}]=rquad(N,k-1);
> end
>
> [Q{1:n}]=ndgrid(q{:}); [W{1:n}]=ndgrid(w{:});

(snip)

> It seems that now ndgrid only returns the first argument. Is
> there a workaround?

This works for me in R2007a.

w = {1:2, 1:3, 1:4};
n = 3;

[W{1:n}]=ndgrid(w{:})
W =
    [2x3x4 double] [2x3x4 double] [2x3x4 double]

John

Subject: Did ndgrid change?

From: Greg von Winckel

Date: 13 Dec, 2007 11:32:42

Message: 6 of 6

Thanks, John. I don't know why I was getting this odd
result, but it seems to be behaving now.

"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <fjoip2$cfi$1@fred.mathworks.com>...
> "Greg von Winckel" <gregvw@gmail.com> wrote in message
> <fjocab$nqi$1@fred.mathworks.com>...
> > I had this bit of code which used to work in a previous
> > version of MATLAB but no longer functions in the current
> > version
> >
> > for k=1:n
> > [q{k},w{k}]=rquad(N,k-1);
> > end
> >
> > [Q{1:n}]=ndgrid(q{:}); [W{1:n}]=ndgrid(w{:});
>
> (snip)
>
> > It seems that now ndgrid only returns the first argument. Is
> > there a workaround?
>
> This works for me in R2007a.
>
> w = {1:2, 1:3, 1:4};
> n = 3;
>
> [W{1:n}]=ndgrid(w{:})
> W =
> [2x3x4 double] [2x3x4 double] [2x3x4 double]
>
> John

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us