Effacer les filtres
Effacer les filtres

How to add "..." to multiple lines

6 vues (au cours des 30 derniers jours)
Greg
Greg le 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

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 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 commentaire
Greg
Greg le 4 Nov 2011
Ah! Thanks. I had no idea you don't need the ";..." when writing matrices on multiple lines. That is fantastic.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by