comparision data in matlab
2 次查看(过去 30 天)
显示 更早的评论
this is first file
4.0004000e+02 2.2576667e+03
4.0006000e+02 2.7194000e+03
4.0008000e+02 2.9347143e+03
4.0010000e+02 3.0555556e+03 &
this is second file
400.04 0.2702
400.05 0.27026
400.06 0.27031
400.07 0.27036
400.08 0.27041
in this both files first colomn is of wavelength and other one is of intensity. i got the wavelength which are same in both files say 400.04 400.06 etc.. but in both files intensity is different corresponding to that same wavelength. so now i want the table in which i got first colomn is of wavelength which are common in both file second colomn is of intensity which is in file 1 corresponding to common wavelength and 3rd colomn is of intensity which is in file 2.
0 个评论
采纳的回答
Star Strider
2021-3-13
I am not certain of the result you want.
Try this:
File1 = [4.0004000e+02 2.2576667e+03
4.0006000e+02 2.7194000e+03
4.0008000e+02 2.9347143e+03
4.0010000e+02 3.0555556e+03];
File2 = [400.04 0.2702
400.05 0.27026
400.06 0.27031
400.07 0.27036
400.08 0.27041];
File1_intrp = interp1(File1(:,1), File1(:,2), File2(:,1));
CombinedFiles = [File2(:,1) File2(:,2), File1_intrp]
producing:
CombinedFiles =
400.04 0.2702 2257.7
400.05 0.27026 2488.5
400.06 0.27031 2719.4
400.07 0.27036 2827.1
400.08 0.27041 2934.7
If you want the opposite result:
File1_intrp = interp1(File2(:,1), File2(:,2), File1(:,1), 'linear','extrap');
CombinedFiles = [File1(:,1) File1(:,2), File1_intrp]
producing:
CombinedFiles =
400.04 2257.7 0.2702
400.06 2719.4 0.27031
400.08 2934.7 0.27041
400.1 3055.6 0.27051
One of these should do what you want.
更多回答(4 个)
Jan
2021-3-13
I have posted the code almost as you need it in your other question:
[Common, iA, iB] = intersect(A(:, 1), B(:, 1));
A(:, 3) = NaN;
A(iA, 3) = B(iB, 2)
A problem can be, that the imported string "4.0004000e+02" need not be exactly the same as 400.04, when rounding errors occur. If there are tiny differences, use round and a sufficient number of decimals.
0 个评论
r r
2021-5-11
I have two files with similar data and I want to extract them into a file, and I also want to print the same line for the same data in the two files
Please help me
F1 = fopen('E.txt');
T1 = textscan(F1,'%s', 'delimiter', '\n');
fclose(F1);
F2 = fopen('G.txt');
tt2 = textscan(F2,'%s', 'delimiter', '\n');
fclose(F2);
T1s = char(T1{:});
T2s = char(T2{:});
[C,ix,ic] = intersect(T1s,T2s,'rows')
%%%%%%%%%%%%%%%%%%out Fiel :::
dlmwrite('R.txt',C,'%.6f');
0 个评论
r r
2021-5-11
I have two files in which there are numbers in the first column that are similar and I want to print the line that matches and differs in the number of the first column in the two files:
%%%%%%%%%%%%%%%%%%%%%%% Fiel.1
fid1 = fopen( 'E1.txt', 'rt' );
T1 = textscan(fid1,'%s', 'delimiter', '\n');
%codes1 = textscan( fid1, '%*s%*s%*s%*s%*s%*s%s', 'Delimiter','|' );
fclose( fid1 );
%%%%%%%%%%%%%%%%%%%%%%%%%%Fiel.2
fid2 = fopen( 'G1.txt', 'rt' );
T2 = textscan(fid2,'%s', 'delimiter', '\n');
%codes2 = textscan( fid2, '%*s%*s%*s%*s%*s%*s%s', 'Delimiter','|' );
fclose( fid2 );
%%%%%%%%%%%%%%%%%%%%%%%%%%%
T1s = char(T1{:});
T2s = char(T2{:});
%Similar data between two files::
%[C,ix,ic] = intersect(T1s,T2s,'rows')
%Differences data between two files::
[B,ib,ib] = visdiff(T1s,T2s,'rows')
%%%%%%%%%%%%%%%%%%%%print output:::
fid = fopen( 'Similar.txt', 'wt' );%Print all similar lines
fprintf('%s\n',C)
fclose( fid ) ;
fid = fopen( 'Different.txt', 'wt' );%Print all different lines
fprintf('%s\n',B)
fclose( fid );
0 个评论
r r
2021-5-11
编辑:Walter Roberson
2021-5-12
%%%I want to print the line for the first column that shares the same number for the two filesd=load('E1.txt');
x1=d(:,1);
x2=d(:,2);
x3=d(:,3);
x4=d(:,4);
x5=d(:,5);
x6=d(:,6);
u=load('G1.txt');
x11=d(:,1);
x21=d(:,2);
x31=d(:,3);
x41=d(:,4);
x51=d(:,5);
x61=d(:,6);
% indices = find(x1(:,1) == x11(:,1));
%fid = fopen('cc.txt','wt');
%fprintf(fid, '%s ', indices);
%fprintf(fid, '\n');
%%%%%%%%%%%%%or%%%%%%%%or
if x11(:,1) == x1(:,1)
fid = fopen('cc.txt','wt');
fprintf(fid, '%s ', indices);
fprintf(fid, '\n');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!