How do I format adding columns to a matrix in a textfile or in general
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
kollin poindexrer
el 26 de Jun. de 2017
Respondida: Jess Lovering
el 26 de Jun. de 2017
So I have a matrix that I am printing to a file that looks like this
1, 2, 3;
6, 7, 8;
11,12,13;
I want to add a two column vectors of the form
[4 ;9 ;14] and [5 ;10 ;15]
to make the updated file look like
1, 2, 3, 4, 5;
6, 7, 8, 9,10;
11,12,13,14,15;
I am running a while loop to get the column vectors so I either have to update the matrix i the while loop before printing it, I dont know the code syntax to do that, or update the matrix in the file after each while loop, this seems easier to place in my code, but I don't know the syntax on how to code this. If anyone could offer help on this issue I would appreciate it. (I dont know how to format matrices in this Q&A so I apologize if this question is hard to look at).
4 comentarios
Respuesta aceptada
Jess Lovering
el 26 de Jun. de 2017
If you wanted to append the file in that manner over each loop then you would have to read in each line, add to the line, and write to a new file - not a very efficient way to do it. I don't think that you can just add to the end of each line simply like you would like to do. You would be better off adding the data to your matrix in the loop and writing the file at the end. You can use the cat function to concatenate the new array to the main matrix pretty easily. Type "doc cat" at your command prompt to pull up the help on this.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!