New to MATLAB trying to convert a series of numbers in a column from wavelength to frequency

1 view (last 30 days)
I'm new to MATLAB trying to convert a series of numbers in a column from wavelength to frequency. I have no idea how to input formulas or to convert (I simply know that w=c/f) I don't even know if c is a value matlab automatically knows

Answers (1)

Star Strider
Star Strider on 22 Nov 2014
Since ‘c’ generically is the speed of propagation of something with wave characteristics, MATLAB can’t guess what you’re thinking. If ‘c’ is the speed of light and since it varies with the medium it’s traversing, it also can’t guess that.
You will need to specify the speed of light for your application, then use element-wise division for your vector.
The equation is:
f = c./w;
  2 Comments
Andan Eddy
Andan Eddy on 23 Nov 2014
Thanks I still don't know whether I put that equation at the top of a blank document. If I label a column w underneath that column and define c. will Matlab know to convert every number in the column from w to f?
Star Strider
Star Strider on 23 Nov 2014
Edited: Star Strider on 23 Nov 2014
My pleasure!
You have to define both ‘c’ and ‘w’ first, then the formula:
% SCRIPT STARTS HERE
c = 2.99792458E+8; % Speed Of Light (m/s)
w = [41:0.5:42.5]'; % Data Vector of Wavelengths (m)
f = c./w; % Frequency (Hz)
This produces a column vector of frequencies approximately spanning the 40m amateur radio band.
An alternative way of doing it is to use an anonymous function:
freq = @(w) 2.99792458E+8./w;
then call it as:
f = freq(w);
You have to define the function at the beginning of your code, then you can use it anywhere in your code after that.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!