how to subtract the numeric data stored in two files
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi,i have two files which consists of numeric data which is stored in 4-columns in each file, where each column represents a particular parameter.How can i subtract the 1st column of the first file with the 1st column of the 2nd file,similarly 2nd column of the first file with the 2nd column of the 2nd file and so on....and the resultant columns should be stored in the new file... I would be greatfull if somebody assists me in solving this problem Thank you in advance.
채택된 답변
Geoff Hayes
2014년 7월 6일
댓글 수: 11
The matrices which are stored in the files are not in equal dimensions!!can you tell me how can i subtract them after reading from dlmread command?
Is the dimension difference due to there being a different number of rows or a different number of columns?
its due to different number of rows!
Since both matrices have the same number of columns, then determine which matrix has more rows (use size) and then just subtract a subset of those rows from the other matrix. For example,
A = [1 2 3; 4 5 6];
B = [2 4 6; 4 5 6; 7 8 9];
C = A - B(1:2,:);
In the above, B has more rows than A, so when we do the subtraction, we just consider the first two rows of B via 1:2 and all columns of B via :.
ya but the matrices will generate dynamically in two files with in a for loop!can u guide me how can i code it for any general case?
Type doc size to see how this function can help. Try to do it, and if it doesn't work the way you expect, post your code and I will try to guide you.
Basically i am trying to compare a given transformed audio input with the original audio present in the database and to determine how much similar it will be with the original audio.for this i will calculate the spectral features(centroid,energy,roll_off,flux) of the two audios and will store them in the file called spectral1.doc(i/p) and file1,file2,file3.....so on(for original audios) and then i will calculate the eucledian distance b/w the i/p file matrix and all the files generated for my original audios and the minimum distance will give me the most similar audio for the given input..is my approach for solving my problem rite? and i am stuck in b/w for achieving it!!!
THIS IS MY CODE!!!
filelist = dir('*.wav');
result = zeros(size(filelist));
for index = 1 : length(filelist) fprintf('Processing %s\n', filelist(index).name); result = zeros(size(filelist)); for index = 1 : length(filelist) fprintf('Processing %s\n', filelist(index).name); [y, fs] = wavread(filelist(index).name);
[signal] =y; fs=44100; windowLength=512; frameRate = 100; step=441; signal = signal / max(abs(signal)); curPos = 1; L = length(signal); numOfFrames = floor((L-windowLength)/step) + 1; c=0.8; % threshold cen_present=1; energy_present=1; roll_Pos=1; fluxpos=1; H = hamming(windowLength); m = ((fs/(2*windowLength))*[1:windowLength])'; Centroid = zeros(1,numOfFrames); Energy=zeros(1,numOfFrames); Rolloff=zeros(1,numOfFrames); Flux=zeros(1,numOfFrames); for i=1:numOfFrames cen_window = H.*(signal(cen_present:cen_present+windowLength-1)); FFT = (abs(fft(cen_window,2*windowLength))); FFT = FFT(1:windowLength); FFT = FFT / max(FFT); Centroid(i) = sum(m.*FFT)/sum(FFT); if (sum(cen_window.^2)<0.010) Centroid(i) = 0.0; end cen_present = cen_present + step;
% short time energy of signal is calculated
energy_window = (signal(energy_present:energy_present+windowLength-1));
Energy(i) = (1/(windowLength)) * sum(abs(energy_window.^2));
energy_present = energy_present + step;
% spectral roll off calculation
roll_window = (signal(roll_Pos:roll_Pos+windowLength-1));
FFT1 = (abs(fft(roll_window,512)));
FFT1 = FFT1(1:255);
totalEnergy = sum(FFT1);
curEnergy = 0.0;
countFFT1 = 1;
while ((curEnergy<=c*totalEnergy) && (countFFT1<=255))
curEnergy = curEnergy + FFT(countFFT1);
countFFT1 = countFFT1 + 1;
end
Rolloff(i) = ((countFFT1-1))/(fs/2);
roll_Pos = roll_Pos + step;
% procedure to calculate Spectral flux begins here
flux_window = H.*(signal(fluxpos:fluxpos+windowLength-1));
FFT2 = (abs(fft(flux_window,2*windowLength)));
FFT2 = FFT2(1:windowLength);
FFT2 = FFT2 / max(FFT2);
if (i>1)
Flux(i) = sum((FFT2-FFTprev).^2);
else
Flux(i) = 0;
end
if (isnan(Flux(i)))
Flux(i)=0;
end
fluxpos = fluxpos + step;
FFTprev = FFT2;
end Centroid = Centroid / (fs/2); nam=sprintf('file%d',index); fid=fopen(nam,'w'); [r col]=size(Centroid); for ii=1:1:col %fprintf(fid,'\n%f',Centroid(ii)); fprintf(fid,'\n%f\t%f\t%f\t%f',Centroid(ii),Energy(ii),Rolloff(ii),Flux(ii)); end fclose(fid);
sorry for the bad alignment of my code...i tried to align it properly but it is getting uploaded in this way!!!
Rahul - the above code and request to review it falls outside the scope of the original question, and will be confusing for future readers of this question. Please create a new post outlining the problem you are experiencing with your code and the help that you are looking for.
As for formatting, highlight the code and press the {}Code button.
ya! i selected my code and pressed {}code button but still i am not getting it!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
