Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Scorp
Scorp le 31 Août 2022
Modifié(e) : Matt J le 31 Août 2022
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 |
% **********************************************************

Réponse acceptée

Matt J
Matt J le 31 Août 2022
Modifié(e) : Matt J le 31 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Analyze Simulation Results dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by