For loop overwrites values in signal

1 次查看(过去 30 天)
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by