help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: elegant solution to address an element of an array [newbie]


From: William Krekeler
Subject: RE: elegant solution to address an element of an array [newbie]
Date: Fri, 4 Feb 2011 17:52:20 +0000

Nukey,

 

you want

 

index = find( f == 27500 ); % fails if 27500 doesn't exist, note you had = not == which is required

 

or

 

[ minValue, index  ] = min ( abs(f - 27500) );         % grabs the value nearest 27500 if 27500 doesn't exist

 

desiredValue = An(index)

 

Bill Krekeler

 

From: address@hidden [mailto:address@hidden On Behalf Of BVBA NuKey Music
Sent: Friday, February 04, 2011 8:54 AM
To: address@hidden
Subject: elegant solution to address an element of an array [newbie]

 

I am looking for  a more elegant solution to the following problem
f=26e3:0.1:31e3;
An=2*A*abs(sin(pi*f*50e-6))./(pi*400e-6*f);
%I then look for the index of the value corresponding with f=27500
%In fact I first wrote f27500_i=find(27500=f), but that doesn't work:
f27500_i=find((27499.9<f) & (f<27500.1));
%determine value of An for 27500Hz in dB
fprintf('value of An for 27500Hz in dB is:'),disp(20*log10(An(f27500_i)/sqrt(2)))

thanks in advance
nukey


reply via email to

[Prev in Thread] Current Thread [Next in Thread]