adding a label to a list of values
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have an m-file that will output a row of values to the same output file repeatedly, thus adding a new row each time I run this m-file. I need to label each new row with a unique identifier so later I remember which row corresponds to what set of data. Ideally I would like each row to look like this: Idenifier value1 value2 value3. However, I don't know where in my code I should add the identifier info to get the end result. Any ideas?
Here is the code I have so far, it's tested and it works.
p = [p1 p2 p3];
load('PlottingMatrix.txt');
plottingmatrix = PlottingMatrix;
plottingmatrix = [plottingmatrix
p];
dlmwrite('PlottingMatrix.txt', plottingmatrix)
0 comentarios
Respuesta aceptada
Fangjun Jiang
el 25 de Sept. de 2011
dlmwrite() can only write matrix. What you need is a cell array that can combine string and numerical data, such as
a={'xdc1658',1,2,3}
To write that type data, fprintf() is more suitable. Check fopen(), fclose() too for examples.
Another hint is that you don't have to read and write previous data again and again, you can use fopen('PlottingMatrix.txt','wta') to specify that you want to append the text file. You only need to write the new data and it will be appended to the end of file.
1 comentario
Jan
el 25 de Sept. de 2011
+1: Agreed. FPRINTF is not only better than LOAD and DLMWRITE, it even works.
Más respuestas (2)
Ver también
Categorías
Más información sobre Characters and Strings 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!