Saving new data in the next line .mat
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi all,
I have a problem, i have writen a code that gets my previus data and stores it in .mat.
The code is :
if exist('table.mat','file')
dataCell = [name,num2cell(trez),num2cell(score)];
save('table.mat', '-append','dataCell');
else
dataCell=[name,num2cell(trez),num2cell(score)];
colNames={'Name','R','G','B','Shape'};
uisave({'colNames','dataCell'},'table');
end
So when get the first data in let say this :
Name | R | G | B | Shape |
Orange | 239 | 135 | 2 | 0.87 |
Then when i won't to save another the data to another row it deletes my previus data. Let's say my second information is :
Apple | 100 |31 |56 | 0.79
It deletes the information about orange.
So my question is how can I write the information so that it saves like it would on a normal database so that every new information set goes under the old information.
Cheers
댓글 수: 0
답변 (1개)
Walter Roberson
2012년 8월 27일
If you are going to use save() or uisave() then you will need to read in the old data, do the appending in memory, and then write out the combined data.
The -append flag for save() completely overwrites any existing variables of the same name; it does not append values to existing matrices.
save() always works on entire variables at a time.
If you are using a new enough version of MATLAB, you could consider using MatFile objects, but those are likely "overkill" for what you are trying to do.
Have you considered using text files instead, and opening them with 'at' permissions to append to them?
참고 항목
카테고리
Help Center 및 File Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!