Saving new data in the next line .mat

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

Réponses (1)

Walter Roberson
Walter Roberson le 27 Août 2012

0 votes

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?

1 commentaire

asd
asd le 27 Août 2012
Hi,
Ill try to do that. About using text file i am creating a apllication for fruit recognization so i need to gather data. I am using KNN to compare present data with the data gathered in the table. So is it smart to use save() or to use something else and import the data?

Connectez-vous pour commenter.

Catégories

En savoir plus sur View and Analyze Simulation Results dans Centre d'aide et File Exchange

Tags

Question posée :

asd
le 27 Août 2012

Community Treasure Hunt

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

Start Hunting!

Translated by