How do I append row(s) of data to an existing array in a .mat file. The following works except the 2nd to last line:
tableIt = [1 2 3;4 5 6;7 8 9];
tableMore = [10 11 12];
filename = 'aTable.mat';
data2store = 'tableIt';
more2store = 'tableMore';
save(filename,data2store');
whos('-file',filename);
m = matfile(filename,'Writable',true);
m.tableIt(end+1,:) = more2store;
whos('-file',filename);

4 comentarios

Walter Roberson
Walter Roberson el 9 de Nov. de 2019
save(filename, data2store, '-v7.3');
without the -v7.3, the .mat file would typically default to -v7 and those are not writable.
Brent
Brent el 9 de Nov. de 2019
-7.3 doesn't solve the error message the code above generates:
Error using ScratchPad (line 12)
The size of the right hand side did not match the size of the indexing on the left hand side.
Walter Roberson
Walter Roberson el 9 de Nov. de 2019
It is recommended to not use end in this context. See https://www.mathworks.com/help/matlab/ref/matlab.io.matfile.html
Brent
Brent el 9 de Nov. de 2019
I'm looking for something that does work, do you know an alternative that works?

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Nov. de 2019

1 voto

more2store = 'tableMore';
That is a 1 x 9 character vector.
tableIt = [1 2 3;4 5 6;7 8 9];
That is a 3 x 3 double.
m.tableIt(end+1,:) = more2store;
That attempts to store the 1 x 9 character vector into 3 columns of a double. That does not fit.

4 comentarios

Brent
Brent el 9 de Nov. de 2019
tableIt is a 3x3 double. I'm then trying to add another row which is a 1x3 double.
Walter Roberson
Walter Roberson el 9 de Nov. de 2019
No, you are attempting to store the character vector 'tableMore' rather than the contents of the variable tableMore
Walter Roberson
Walter Roberson el 9 de Nov. de 2019
If you had done
more2store = tableMore;
then it would have worked.
Walter Roberson
Walter Roberson el 9 de Nov. de 2019
http://www.cs.utoronto.ca/~chechik/courses/csc324/white.html

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

el 9 de Nov. de 2019

Comentada:

el 9 de Nov. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by