copy pasting rows of a file to columns of other file

1 回表示 (過去 30 日間)
aditi
aditi 2014 年 4 月 3 日
コメント済み: Chandrasekhar 2014 年 4 月 4 日
I have three files: 1) file1.ap and 2) file2.ap and 3)file3.ap with form as follows:
file1
1 2 3
4 5 6
7 8 9
file2
12 15 16
13 18 19
14 21 22
file3
22
24
33
i want to add 2nd and 3rd column of file 1 & file2 to file3 as rows i.e i want:
22 2 3 5 6 8 9
24 15 16 18 19 21 22
33
please help me with the program.

採用された回答

Chandrasekhar
Chandrasekhar 2014 年 4 月 3 日
clear all;
clc;
fp1 = fopen('f1.ap','r');
i = 1;
while(~feof(fp1))
mat{i,:}= fgetl(fp1);
i = i+1;
end
fclose(fp1);
mat1 = str2num(cell2mat(mat));
mat1=mat1(:,2:3);
mat1 = reshape(mat1',1,6);
fp2 = fopen('f2.ap','r');
i = 1;
while(~feof(fp2))
mat{i,:}= fgetl(fp2);
i = i+1;
end
fclose(fp2);
mat2 = str2num(cell2mat(mat));
mat2 = mat2(:,2:3);
mat2 = reshape(mat2',1,6);
fp3 = fopen('f3.ap','r');
i = 1;
while(~feof(fp3))
mat{i,:}= fgetl(fp3);
i= i+1;
end
mat3 = str2num(cell2mat(mat));
mat3 = [mat3 [mat1;mat2;zeros(1,6)]];
mat2 = num2str(mat3)
fclose(fp3);
mat3 contains the required matrix
  4 件のコメント
aditi
aditi 2014 年 4 月 3 日
hi akshata....could u plz tell me how to do so..m new to MATLAB
Chandrasekhar
Chandrasekhar 2014 年 4 月 4 日
can u attach the data..i can make it for u

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by