Can you save and append to a variable that is a vector in a matfile

3 visualizzazioni (ultimi 30 giorni)
Can you save a variable that is a vector to a matfile or can you only save symmetrical arrays? If you can save a vector can you then append to the end of the variable in the matfile I have tried:
var = [1,2,3,4,5]
var = 1×5
1 2 3 4 5
matFileObj = matfile('myFile.mat', 'Writable', true);
matFileObj.var = var;
if ~isempty(who(matFileObj, 'var'))
varSize = size(matFileObj, 'var', 2);
matFileObj.var(varSize+1,:) = var;
end
this code builds an array that is 5 x 5 instead of 1 x 5 and then appends to the bottom of the rows in the file)
% | 1 2 3 4 5 |
% | 0 0 0 0 0 |
% | 0 0 0 0 0 |
% | 0 0 0 0 0 |
% | 0 0 0 0 0 |
% | 0 0 0 0 0 |
% | 1 2 3 4 5 |
But I want:
% | 1 2 3 4 5 1 2 3 4 5 |
% **********************************************************

Risposta accettata

Matt J
Matt J il 31 Ago 2022
Modificato: Matt J il 31 Ago 2022
if ~isempty(who(matFileObj, 'var'))
matFileObj.var = [matFileObj.var ,var];
end
or,
if ~isempty(who(matFileObj, 'var'))
varSize = size(matFileObj, 'var', 2);
matFileObj.var(1,varSize+(1:numel(var))) = var;
end

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by