Clear Filters
Clear Filters

loop txt files and save files

2 views (last 30 days)
addy fang
addy fang on 10 Jul 2020
Edited: addy fang on 10 Jul 2020
I do not have much knowledge in Matlab, but want to do the following, and need help.
I have two excel files, each has five columns of data. I need to add each column data in these two files with varying percentages in a loop, and save the new data in a series of files with the percentage in the files' names. Example:
%%%%%%%input data1%%%%%%%%%%%%%%%
data1=importdata('rawdata1.txt');
f1=data1(:,1);
e11=data1(:,2);
e12=data1(:,3);
u11=data1(:,4);
u12=data1(:,5);
%%%%%%%input data2%%%%%%%%%%%%%%%
data2=importdata('rawdata2.txt');
f2=data2(:,1);
e21=data2(:,2);
e22=data2(:,3);
u21=data2(:,4);
u22=data2(:,5);
%%%%%%%%%%%%%%%composite data%%%%%%%%%%%%
for x=0:0.1:1
data="Data"+x
f=x*f1+(1-x)*f2;
e1=x*e11+(1-x)*e21;
e2=x*e12+(1-x)*e22;
u1=x*u11+(1-x)*u21;
u2=x*u12+(1-x)*u22;
%%%%%%%%%save in data
data(:,1)=f;
data(:,2)=e1;
data(:,3)=e2;
data(:,4)=u1;
data(:,5)=u2;
xlswrite('data',data);
end;
  9 Comments
Walter Roberson
Walter Roberson on 10 Jul 2020
Notice that what I posted is
xslwrite(filename, data);
What you did instead is
xslwrite('filename', data);
addy fang
addy fang on 10 Jul 2020
Edited: addy fang on 10 Jul 2020
Thank Walter and Madhan a lot for the great help!

Sign in to comment.

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!