필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Scorp
Scorp 2022년 8월 31일
편집: Matt J 2022년 8월 31일
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