Azzera filtri
Azzera filtri

How to avoid data overwrite problem in looping

2 visualizzazioni (ultimi 30 giorni)
addy fang
addy fang il 21 Lug 2020
Modificato: addy fang il 21 Lug 2020
I have some data overwrite problem in looping
%%%%%%%read data%%%%%%%%%%%%%%%
origindata=importdata('rawdata.txt');
f=origindata(:,1);
a=origindata(:,2);
b=origindata(:,3);
c=origindata(:,4);
d=origindata(:,5);
fstep=0.17;
y=0;
for t=(0.1:0.1:20)
e=a-j*b;
u=c-j*d;
rl=u.*e.*f*t/3;
%%%save results in y1, for each t, it save three columns 3*y-2, 3*y-1 and 3*y%%%
y=y+1;
y1(:,3*y-2)=f;
y1(:,3*y-1)=rl;
y1(:,3*y)=t;
%%%select data from three columns 3*y-2, 3*y-1 and 3*y and save in x1, only select those with rl value less than 0%%%
x1=y1(y1(:,3*y-1)<0, :); hold on;
%%%count the number of row in column 3*y-1%%%
n=size(x1,3*y-1);
totalwidth = fstep*(n+4);
%%%write the data in columns 3*y-2, 3*y-1 and 3*y%%%
x1(n+4, 3*y-2:3*y)=[totalwidth 0 t];
hold on;
end;
xlswrite('y1',y1);
xlswrite('x1',x1);
Problems: in x1, the last three column overwrite all previous columns.
Can anyone help me out? Thank you.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by