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

3 次查看(过去 30 天)
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 |
% **********************************************************

采纳的回答

Matt J
Matt J 2022-8-31
编辑:Matt J 2022-8-31
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Analyze Simulation Results 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by