Thread Subject: Can't Append to vector

Subject: Can't Append to vector

From: Joe Nunes

Date: 12 Nov, 2009 16:35:17

Message: 1 of 4

Hello,

i am trying to append the first value of a vector to the end, but it gives me an error =(

??? Subscripted assignment dimension mismatch.

my code is this

for i=1:size(ttriangles,1)
    ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)];
end

what is wrong with this ?

thanks

nunes

Subject: Can't Append to vector

From: Jos

Date: 12 Nov, 2009 16:47:02

Message: 2 of 4

"Joe Nunes" <vazdepaivanunes@gmail.com> wrote in message <hdhdg5$o3t$1@fred.mathworks.com>...
> Hello,
>
> i am trying to append the first value of a vector to the end, but it gives me an error =(
>
> ??? Subscripted assignment dimension mismatch.
>
> my code is this
>
> for i=1:size(ttriangles,1)
> ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)];
> end
>
> what is wrong with this ?
>
> thanks
>
> nunes

Learn to debug:

for i = 1:1
ttriangles(i,:) % a 1-by-N vector
ttriangles(i,1) % a 1-by-1 scalar
[ttriangles(i,:) ttriangles(i,1)] % a 1-by-(N+1) vector
ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)] % which does not fit into a 1-by-N vector
end

Try this:
TT = [TT TT(:,1)]

Jos

Subject: Can't Append to vector

From: Joe Nunes

Date: 12 Nov, 2009 17:10:06

Message: 3 of 4

"Jos " <#10584@fileexchange.com> wrote in message <hdhe66$7s0$1@fred.mathworks.com>...
> "Joe Nunes" <vazdepaivanunes@gmail.com> wrote in message <hdhdg5$o3t$1@fred.mathworks.com>...
> > Hello,
> >
> > i am trying to append the first value of a vector to the end, but it gives me an error =(
> >
> > ??? Subscripted assignment dimension mismatch.
> >
> > my code is this
> >
> > for i=1:size(ttriangles,1)
> > ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)];
> > end
> >
> > what is wrong with this ?
> >
> > thanks
> >
> > nunes
>
> Learn to debug:
>
> for i = 1:1
> ttriangles(i,:) % a 1-by-N vector
> ttriangles(i,1) % a 1-by-1 scalar
> [ttriangles(i,:) ttriangles(i,1)] % a 1-by-(N+1) vector
> ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)] % which does not fit into a 1-by-N vector
> end
>
> Try this:
> TT = [TT TT(:,1)]
>
> Jos

It worked! Thank you!

Subject: Can't Append to vector

From: Joe Nunes

Date: 12 Nov, 2009 17:17:03

Message: 4 of 4

"Jos " <#10584@fileexchange.com> wrote in message <hdhe66$7s0$1@fred.mathworks.com>...
> "Joe Nunes" <vazdepaivanunes@gmail.com> wrote in message <hdhdg5$o3t$1@fred.mathworks.com>...
> > Hello,
> >
> > i am trying to append the first value of a vector to the end, but it gives me an error =(
> >
> > ??? Subscripted assignment dimension mismatch.
> >
> > my code is this
> >
> > for i=1:size(ttriangles,1)
> > ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)];
> > end
> >
> > what is wrong with this ?
> >
> > thanks
> >
> > nunes
>
> Learn to debug:
>
> for i = 1:1
> ttriangles(i,:) % a 1-by-N vector
> ttriangles(i,1) % a 1-by-1 scalar
> [ttriangles(i,:) ttriangles(i,1)] % a 1-by-(N+1) vector
> ttriangles(i,:) = [ttriangles(i,:) ttriangles(i,1)] % which does not fit into a 1-by-N vector
> end
>
> Try this:
> TT = [TT TT(:,1)]
>
> Jos

It worked! Thank you!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
vector append Joe Nunes 12 Nov, 2009 11:39:05
rssFeed for this Thread

Contact us at files@mathworks.com