Clear Filters
Clear Filters

How to add "..." to multiple lines

6 views (last 30 days)
Greg
Greg on 4 Nov 2011
Hi,
I think I have a simple question. I pasted a large number of 3D points into an mfile. There are N >10000 points and each is on a separate line i.e.
1 2 3
4 5 6
7 8 9
...
I want to assign the whole mess to one 3Nx1 vector. Is there an easier way to do this than putting [] around it and ... at the end of each line? That is, is there a way to tell Matlab to ignore line breaks for a section (and say replace them with tabs)? Or another creative solution?
Thanks. It seems a little silly, but I'd love to avoid spending my afternoon pasting "..."s...
-greg

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 4 Nov 2011
There is a better way. I assume you pasted the data so the data has multiple lines. You only need to add one "[" at the beginning of the first line and add one "]" at the end of the last line to make it a matrix. Then you can reshape it to a vector.
a=[1 2 3
4 5 6
7 8 9];
b=a';
b=b(:)
  1 Comment
Greg
Greg on 4 Nov 2011
Ah! Thanks. I had no idea you don't need the ";..." when writing matrices on multiple lines. That is fantastic.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!