I need to save some data to an existing table. So i have column names and one row that has data. Now I get the second set of information and i need to put it in the second row and so on.
Can you just point me where i can find this.
I have done this so far. Played arround with save( -struct) but doesn’t seem to work.
if exist('table.mat','file')
...
...
else
dataCell = [name,trez,score];
colNames = {'Name','R','G','B','Shape'};
uisave({'colNames','dataCell'},'table');
end
So I check if there is table.mat, if there is none it creates it with some passed values. Now table.mat exists I need to put the second values without deleting other values.
UPDATE
OK i made the code like this:
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
But when i do save data using :
dataCell = [name,num2cell(trez),num2cell(score)];
save('table.mat', '-append','dataCell');
It deletes the old entry. Lets say in my table information is as it follows :
Name | R | G | B | Shape |
Orange | 239 | 135 | 2 | 0.87
Then if I try to save another entry like :
Apple | 100 |31 |56 | 0.79
It deletes the Orange. So do i need to add something or use some other method for this kind of information saving?
The
savecommand can take an-appendflag, which allows you to add data to existing files without overwriting old data. However for .mat files-appendonly allows you to add new variables. If you specify a variable name that already exists in the .mat file it will be overwritten.However, if you are saving to an ASCII file then data is simply appended to the end of the file.
This presents you with two options.
Update: After re-reading your original question, I have to ask why not save in a single operation rather than saving line by line?