MATLAB Answers

Add lines (data) to a fopen file without overwriting the previous data

5 views (last 30 days)
Hi, I would like to know please how to add data to an fopen file without overwrting the previous data I am using NS = fopen([‘Valu_Var’ num2str(realiz)’.txt’],’w+’);

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 29 Jun 2020
Edited: Stephen Cobeldick on 29 Jun 2020
Try the append option:
NS = fopen(... ,'a+');
% ^ try this

  2 Comments

Eliane Youssef
Eliane Youssef on 29 Jun 2020
I have another issue that seems to exist. I have a matrix where I am also saving my values and when adding the new lines (lines: y+(tt/0.2)+1), it replaces the old lines (lines: y) by zeros and writes the new lines afterwards.
I am using:
for realiz = 1:...
NS = fopen(['Valu_Var' num2str(realiz) '.txt'],'a+');
for y = 1:...
y;
Var_NS(y+(tt/0.2)+1,realiz)= EvalRandomField(...);
fprintf(NS,'Var(');
fprintf(NS,'%d',y+(tt/0.2)+1); ...
fprintf(NS,'%f\n',Var_NS(y+(tt/0.2)+1,realiz));
end
fclose(NS);
end
save('Var_NS','Var_NS','-v7.3')

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Translated by