Help modifying a User-defined-function

5 visualizzazioni (ultimi 30 giorni)
Vivek
Vivek il 20 Apr 2020
Commentato: Ameer Hamza il 21 Apr 2020
I am trying to compute the mean max and mean min amplitude of time series datasets. These timeseries are arranged in each column of a matrix, so that the matrix is 351x117 . So 117 timeseries. I have found a user defined function that can do just that.The problem is that this UDF is meant for only 1 timeseries array at a time, x. How can I modify the following UDF to accomodate for a matrix,A, instead of an array x. Note that the desired output will be in temp78. I will need to compute the average of the fist two columns of temp78 in order to find the avg max and min amplitudes for every timeseries.
  2 Commenti
Walter Roberson
Walter Roberson il 20 Apr 2020
It is easier for us to work with code than with a picture of code.
Vivek
Vivek il 20 Apr 2020
Here is it. Any help is much appreciated.
% OUTPUT
% temp80 gives sorted wave height and corresponding period
% temp78 gives raw upcrossing info.
% NT is the number of waves
%
% INPUT
% x is the time series of interest
% N is length of time series
% dt is 1/(sampling frequency)
%---------------------------------------------------------------------
function [temp80,temp78,NT]=zero_cross(x,N,dt)
% find zero-crossing points
temp70 = x(1:N-1).*x(2:N);
temp70(N) = 1.0;
temp72=find(temp70<0);
temp73 = zeros(N,1);
temp74 = zeros(N,1);
temp75 = find(x<0);
temp73(temp72) = 1;
temp74(temp75) = 1;
temp76 = and(temp73,temp74);
temp77 = find(temp76>0);
temp555 = temp77/24;
temp78 = zeros(N,4);
% total number of complete waves
NT = sum(temp76)-1;
% find local maxima, minima, duration and occurance
% Hmax Hmin Tdur Tocur
for i = 1:NT;
temp78(temp77(i),1) = max(x(temp77(i):temp77(i+1)));
temp78(temp77(i),2) = min(x(temp77(i):temp77(i+1)));
temp78(temp77(i),3) = temp77(i+1) - temp77(i);
temp78(temp77(i),4) = temp77(i);
end
%output
temp78=temp78(find(temp78(:,4)>0),:); %raw upcrossing data
temp79(:,1)=temp78(:,1)-temp78(:,2); %wave height
temp79(:,2)=temp78(:,3)*dt; %wave period
temp80=flipud(sortrows(temp79,1)); %sorted H and T

Accedi per commentare.

Risposta accettata

Ameer Hamza
Ameer Hamza il 21 Apr 2020
try something like the following code. Save this in a single file named zero_cross.m
function [temp80,temp78,NT]=zero_cross(x,N,dt)
m = size(x,2); % num columns
temp80 = cell(1,m);
temp78 = cell(1,m);
NT = cell(1,m);
for i=1:m
[temp80{i}, temp78{i}, NT{i}] = zero_cross1(x(:,i), N, dt);
end
end
function [temp80,temp78,NT]=zero_cross1(x,N,dt)
% find zero-crossing points
temp70 = x(1:N-1).*x(2:N);
temp70(N) = 1.0;
temp72=find(temp70<0);
temp73 = zeros(N,1);
temp74 = zeros(N,1);
temp75 = find(x<0);
temp73(temp72) = 1;
temp74(temp75) = 1;
temp76 = and(temp73,temp74);
temp77 = find(temp76>0);
temp555 = temp77/24;
temp78 = zeros(N,4);
% total number of complete waves
NT = sum(temp76)-1;
% find local maxima, minima, duration and occurance
% Hmax Hmin Tdur Tocur
for i = 1:NT;
temp78(temp77(i),1) = max(x(temp77(i):temp77(i+1)));
temp78(temp77(i),2) = min(x(temp77(i):temp77(i+1)));
temp78(temp77(i),3) = temp77(i+1) - temp77(i);
temp78(temp77(i),4) = temp77(i);
end
%output
temp78=temp78(find(temp78(:,4)>0),:); %raw upcrossing data
temp79(:,1)=temp78(:,1)-temp78(:,2); %wave height
temp79(:,2)=temp78(:,3)*dt; %wave period
temp80=flipud(sortrows(temp79,1)); %sorted H and T
end

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by