Octave: save vector to next row in csvfile

Viewed 33

Noob question, I'm trying to save results from each iteration into a csv file for later use, however the code keeps overwriting the old data in the csv file for each iteration thus leaving me with only the last results. I'd like it to write the new results on a new row each time the code iterates, any suggestions on how to fix this?

code, please excuse the swedish comments, the actual calculations should not mater to the problem:

%förbered programmet%
clc
clear
close all
cd C:\Octave\Gauss_Newton
Pread=dlmread('C:\Octave\Gauss_Newton\points_1.txt',';',0,0);
%start for loop
max_iters=10
for i = 1 : max_iters
%create random noise
sizeP=size(Pread);
noise=0.002*randn(sizeP(1),sizeP(2))
P=Pread+noise
%linjär lösning%
%hitta mittenpunkten%
Pmid=round(rows(P)/2);
%tag fram L1 och rätvinklig vektor från mitten av L1%
L1=P(Pmid,:)-P(1,:);
L1P=P(1,:)+(L1/2);
L11y=-L1(1)/L1(2);
L11=[1,L11y];
%tag fram L2 och rätvinklig vektor L22 från mitten av L2%
L2=P(Pmid,:)-P(end,:);
L2P=P(end,:)+L2/2;
L22y=-L2(1)/L2(2);
L22=[1,L22y];
%fusk linjer%
L11f=cc_fusk-L1P;
L22f=cc_fusk-L2P;
cc_fuskB=intersectLines([L1P,L11f],[L2P,L22f]);
%hitta mittpunkten för cirkeln%
cc_lin=intersectLines([L1P,L11],[L2P,L22]);
%beräkna möjliga radier%
VR_1=cc_lin-P(1,:);
R_1=sqrt((VR_1(1))^2+(VR_1(2))^2);
VR_2=cc_lin-P(Pmid,:);
R_2=sqrt((VR_2(1))^2+(VR_2(2))^2);
VR_3=cc_lin-P(end,:);
R_3=sqrt((VR_3(1))^2+(VR_3(2))^2);
R_avrg_lin=(R_1+R_2+R_3)/3
%avvikelser
F=[abs(cc_lin(1)-cc_fusk(1)),abs(cc_lin(2)-cc_fusk(2)),abs(R_avrg_lin-R_fusk)]
dlmwrite('resultfile.csv', F,"delimiter", ",", "newline","/n")
end ``
1 Answers
Related