append rows to same .mat file (without replacing)

What is the syntax for appending values to a existing .mat file? When I use -append, I end up replacing the values!
Example: %% code updated %%
for col = 1:10
out = zeros(1,1000000); %reset out to zero vector
x=randn(1,100000);
out(col,:)=x.^2;
if col == 1
filename='z.mat';
save(filename,'out','-v7.3'); % Write to MAT file
else
save(filename,'out','-v7.3','-append');
end
end
After running the above code, I have a .mat file out(10x100000) but it contains only the saved values of last column (rest zeros). That is, each time I zero the out variable, the same is written to file also. I want to save all the values without holding them in variable out (due to memory constrains) . How can I do this?
What am I missing? please locate in my code.

 採用された回答

Geoff
Geoff 2012 年 3 月 22 日

1 投票

From the documentation on save:
'-append': Add data to an existing file.
Does your file exist?
if col == 1
save(filename,'out','-v7.3');
else
save(filename,'out','-v7.3','-append');
end

2 件のコメント

zozo
zozo 2012 年 3 月 22 日
thank you @Geoff
zozo
zozo 2012 年 3 月 22 日
@geoff: There is still a problem. (please have a look at the updated question above)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

タグ

質問済み:

2012 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by