matlab: cut out certain rows from data into new matrix
I have few raw_data file similar as below...each.dat file has different number of rows...However, in each raw_data file, the first 2 rows and last 2 rows will be moved into angle_data.dat file...so that after programming through matlab code, each raw_data file will create 2 new fi开发者_C百科les: one is angle_data file and another is final_data file...(final_data file is the remaining data from raw_data file)...
raw_data1.dat
A B 0.0 1.2222 3.1111
C U 0.0 2.333 12.999
G T 3.4 2.3 5.666
R P 2.5 44.3 6.777
R Q 8.222 5.999 0.344
After programming through matlab code, result as below:
angle_data1.dat
A B 0.0 1.2222 3.1111
C U 0.0 2.333 12.999
R P 2.5 44.3 6.777
R Q 8.222 5.999 0.344
final_data1.dat
G T 3.4 2.3 5.666
Something like the following should work:
angleData=rawData(1:2;end-1:end);
finalData=rawData(3:end-2);
I might have swapped rows and columns there, but that's the idea. I don't have a copy of matlab on this machine to test it.
EDIT: just in case:
angleData=rawData(:,1:2;:,end-1:end);
finalData=rawData(:,3:end-2);
Though.. if you have a shell available, it'd probably be a lot faster to do: (Thanks to Amro for the improved last line)
head -n 2 raw_data.dat > angle_data.dat
tail -n 2 raw_data.dat >> angle_data.dat
head -n -2 raw_data.dat | tail -n +3 > final_data.dat
精彩评论