For loop overwrites values in signal

조회 수: 1 (최근 30일)
Ben
Ben 2020년 3월 11일
댓글: Star Strider 2020년 3월 16일
Hi,
I have vibration signal measured on rotating machinery consiting of 1D values (length 13000). I have 50 wav files, which I have now processed and stored in one termed x - each column in x is a serperate wave file measuring the machinery at a different time (so x is 50 columns).
I would like to rapidly process each of the wave files stored in x and store the output in to several .mat files representing each analysis. An example of what I want I am trying to acheive is below. I manage to get the loop through each 50 columns, but on each occasion it overwrites the ouput file. Please can anyone advise on how I can individually analyse each column and save.
Any help is appreciated, thanks alot.
for ii= 1:50
max=max(x(:,ii); % ideally this would save the max of x all in one file called 'max', each column corresponding to the max of each wav file stored in x.
rms=rms(x(:,ii)); % ideally this would save the rms of x all in one file called 'rms', each column corresponding to the rms of each wav file stored in x.
% and further analysis can be performed here.
end

채택된 답변

Star Strider
Star Strider 2020년 3월 11일
First, please do not use ‘max’ as a variable name. It is the name of the max function (obviously) and variable names take precedence over function names in MATLAB. This is called ‘overshadowing’ a MATLAB function name, and is to be avoided. (I am surprised that your code actually works beyond the first iteration because of that.)
Second, subscript the results:
maxv = zeros(1,50)
rmsv = zeros(1,50);
for ii= 1:50
maxv(ii) = max(x(:,ii); % ideally this would save the max of x all in one file called 'max', each column corresponding to the max of each wav file stored in x.
rmsv(ii) = rms(x(:,ii)); % ideally this would save the rms of x all in one file called 'rms', each column corresponding to the rms of each wav file stored in x.
% and further analysis can be performed here.
end
That should work, and give you correct results.
Since MATLAB uses column-major evaluations,.you might be able to do that entirely without the loop:
maxv = max(x);
rmsv = rms(x);
  댓글 수: 2
Ben
Ben 2020년 3월 16일
Thanks, that worked!
Star Strider
Star Strider 2020년 3월 16일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by