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

3 Ansichten (letzte 30 Tage)
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 |
% **********************************************************

Akzeptierte Antwort

Matt J
Matt J am 31 Aug. 2022
Bearbeitet: Matt J am 31 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Analyze Simulation Results finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by