For loop overwrites values in signal

1 Ansicht (letzte 30 Tage)
Ben
Ben am 11 Mär. 2020
Kommentiert: Star Strider am 16 Mär. 2020
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

Akzeptierte Antwort

Star Strider
Star Strider am 11 Mär. 2020
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 Kommentare
Ben
Ben am 16 Mär. 2020
Thanks, that worked!
Star Strider
Star Strider am 16 Mär. 2020
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by