http://stackoverflow.com/questions/3071558/how-can-i-merge-this-data-in-matlab
my question is related to the above link.
With the code below (thanks gnovice), it will create a new file with 3 column (overwrite column time
). Instead of overwrite column time
I want to add the modified time
as a new column..which makes the new file =4 columns [a time c modifiedTime].
a = [1; 2; 3; 4; 5]; %# Sample data
time = [10; 40; 20; 11; 40]; %# Sample data
c = [0; 1; 0; 0; 1]; %# Sample data
index = find(c == 1); %# Find indices where c equals 1
temp = time(index); %# Temporarily store the time values
time(index) = 0; %# Zero-out the time points
time(index-1) = time(index-1)+temp; %# Add to the previous time points
c(index) = 0; %# Zero-out the entries of c
fid = fopen('newData.txt','wt'); %# Open the file
fprintf(fid,'%g\t %g\t %g\n',[a time c].'); %'# Write the data to the file
fclose(fid); %# Close the file