Relation operation between two arrays
Relation operation between two arrays
(OP)
Hi,
Im trying to compare two arrays - I want to compare each element separately to the corresponding element in the other array and use the answer as part of an if statement. This is what im doing so far that doesnt work:
if PeakEnv >=level
gain = (level/PeakEnv)^0.75
else
gain = 1
end
have also tried putting if PeakEnv(1:88200)>=level but that doesnt work either. it evaluates the whole array and then makes the condition false for the whole thing.
have done the thing with for loops and it works fine but takes ages.
any suggestions??
thanks
jen
Im trying to compare two arrays - I want to compare each element separately to the corresponding element in the other array and use the answer as part of an if statement. This is what im doing so far that doesnt work:
if PeakEnv >=level
gain = (level/PeakEnv)^0.75
else
gain = 1
end
have also tried putting if PeakEnv(1:88200)>=level but that doesnt work either. it evaluates the whole array and then makes the condition false for the whole thing.
have done the thing with for loops and it works fine but takes ages.
any suggestions??
thanks
jen





RE: Relation operation between two arrays
idx=peakEnv>=level;
gain(idx)=(level(idx)./PeakEnv(idx)).^0.75;
gain(~idx)=1;
RE: Relation operation between two arrays
gain = ones( size( PeakEnv ) ); % malloc and part of work
indexOverLevel = find( PeakEnv >= level );
gain( indexOverLevel ) = ( level / PeakEnv( indexOverLevel ) ) .^ 0.75
% Notice the .^ instead of just ^
That is for point by point instead of a matrix exponential.
RE: Relation operation between two arrays
% Assuming level is a scalar
gain = ones( size( PeakEnv ) ); % malloc and part of work
indexOverLevel = find( PeakEnv >= level );
gain( indexOverLevel ) = ( level ./ PeakEnv( indexOverLevel ) ) .^ 0.75
% Notice the .^ instead of just ^
That is for point by point instead of a matrix exponential.
RE: Relation operation between two arrays
There's no need for the find() call in your code. It just adds a little overhead.
RE: Relation operation between two arrays
Thanks! I learned something new. I didn't know you could say idx=peakEnv>=level;
Also, I didn't know you had already answered this. I did not see your post when I sent mine. There must have been a slight delay
RE: Relation operation between two arrays
It's a dull day when I don't learn something new!
RE: Relation operation between two arrays
works a treat.
jenxx
RE: Relation operation between two arrays
Because the logical indexing above compares the vectors that dont change im kind of stuck!
any help would be appreciated
jen x
RE: Relation operation between two arrays
RE: Relation operation between two arrays