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:
Concatenate problem

Subject: Concatenate problem

From: ravi

Date: 18 Feb, 2010 18:58:04

Message: 1 of 4

for k = 1:length(lines)
nm = [lines(k).point1; lines(k).point2];
end

In my above code, my output is

nm =
            3 5
            4 9

nm =
           44 2
             8 32


However, I actually want to get my code to output

nm =
                  3 5 44 2
                  4 9 8 32

I tried using this

      nm = [cat(1,lines(k).point1); cat(1,lines(k).point2)];


but it didnt work as i got the same result.


Help please.
ravi
                         

Subject: Concatenate problem

From: Sadik

Date: 18 Feb, 2010 19:07:22

Message: 2 of 4

This should do it:

nm = [];
for k = 1:length(lines)
    nm = [nm;lines(k).point1; lines(k).point2];
end



"ravi " <ravi_071@hotmail.com> wrote in message <hlk2js$3ck$1@fred.mathworks.com>...
> for k = 1:length(lines)
> nm = [lines(k).point1; lines(k).point2];
> end
>
> In my above code, my output is
>
> nm =
> 3 5
> 4 9
>
> nm =
> 44 2
> 8 32
>
>
> However, I actually want to get my code to output
>
> nm =
> 3 5 44 2
> 4 9 8 32
>
> I tried using this
>
> nm = [cat(1,lines(k).point1); cat(1,lines(k).point2)];
>
>
> but it didnt work as i got the same result.
>
>
> Help please.
> ravi
>

Subject: Concatenate problem

From: ravi

Date: 18 Feb, 2010 19:32:20

Message: 3 of 4

sadik,


I tried your suggestion.


nm=[]
for k = 1:length(lines)
 nm = [nm;lines(k).point1; lines(k).point2];
 end



But I now get the following results


> nm =
            3 5
            4 9
            3 5
            4 9


> nm =
             44 2
             8 32
            44 2
             8 32

Subject: Concatenate problem

From: Sadik

Date: 18 Feb, 2010 20:04:06

Message: 4 of 4

You are not revealing all of the code you have. :))

You are running the code with two "lines" it seems...

1. There are repetitions in your "lines" [double counting the points]
2. You should use nm = []; only once. After you run the for loop for the first "lines", you should run the for loop for the second one without typing nm =[]; in between.

Best.



"ravi " <ravi_071@hotmail.com> wrote in message <hlk4k4$fml$1@fred.mathworks.com>...
> sadik,
>
>
> I tried your suggestion.
>
>
> nm=[]
> for k = 1:length(lines)
> nm = [nm;lines(k).point1; lines(k).point2];
> end
>
>
>
> But I now get the following results
>
>
> > nm =
> 3 5
> 4 9
> 3 5
> 4 9
>
>
> > nm =
> 44 2
> 8 32
> 44 2
> 8 32

Tags for this Thread

No tags are associated with 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