(New page: == General Tips == When dealing with multimedia in MATLAB it is always a good idea to end every command with a semicolon. Use <pre> [data, sample_rate, bits_per_sample] = wavread('c:\pat...) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
− | Start every MATLAB program with the | + | Start every MATLAB program with the commands clear and clc. |
+ | <pre> | ||
+ | # clear memory | ||
+ | clear | ||
− | clear | + | # clear console |
− | clc | + | clc |
+ | </pre> | ||
== Useful Commands == | == Useful Commands == | ||
− | Functions for interacting with wav files: | + | ==== Functions for interacting with wav files ==== |
+ | <pre> | ||
+ | #Read a wav file: | ||
+ | [data, sample_rate, bits_per_sample] = wavread('c:\path\to\file\filename.wav'); | ||
+ | </pre> | ||
+ | <pre> | ||
+ | #Play the data from a wav file: | ||
+ | wavplay(data, sample_rate); | ||
+ | sound(data, sample_rate); | ||
+ | </pre> | ||
+ | <pre> | ||
+ | #Save a wav file: | ||
+ | wavwrite(data,sample_rate,bits_per_sample,'/path/to/file/filename.wav'); | ||
+ | </pre> | ||
− | |||
− | |||
− | + | ==== Reverse the data in a vector ==== | |
− | + | <pre> | |
− | + | # Reverse a row vector | |
+ | row_vector = fliplr(row_vector); | ||
− | + | # Reverse a column vector | |
− | + | col_vector = flipud(col_vector); | |
+ | </pre> | ||
− | + | NOTE: The vector returned by wavread is a column vector. flipud must be used to reverse it. | |
− | + | ||
− | + | ||
− | Convert a row vector to a column vector and vice versa | + | |
− | + | ==== Convert a row vector to a column vector and vice versa ==== | |
− | + | <pre> | |
+ | #Convert a column vector to row vector. | ||
+ | row_vector = rot90(col_vector); | ||
+ | |||
+ | #Convert a row vector to a column vector. | ||
+ | col_vector = rot90(row_vector); | ||
+ | </pre> |
Latest revision as of 07:14, 3 September 2008
Contents
General Tips
When dealing with multimedia in MATLAB it is always a good idea to end every command with a semicolon. Use
[data, sample_rate, bits_per_sample] = wavread('c:\path\to\file\filename.wav');
instead of
[data, sample_rate, bits_per_sample] = wavread('c:\path\to\file\filename.wav')
A semicolon keeps MATLAB from echoing the output of a command to the console window. Use a semicolon if you do not want to wait for 10s worth of data sampled at 44100 samples per second scroll by your screen.
Start every MATLAB program with the commands clear and clc.
# clear memory clear # clear console clc
Useful Commands
Functions for interacting with wav files
#Read a wav file: [data, sample_rate, bits_per_sample] = wavread('c:\path\to\file\filename.wav');
#Play the data from a wav file: wavplay(data, sample_rate); sound(data, sample_rate);
#Save a wav file: wavwrite(data,sample_rate,bits_per_sample,'/path/to/file/filename.wav');
Reverse the data in a vector
# Reverse a row vector row_vector = fliplr(row_vector); # Reverse a column vector col_vector = flipud(col_vector);
NOTE: The vector returned by wavread is a column vector. flipud must be used to reverse it.
Convert a row vector to a column vector and vice versa
#Convert a column vector to row vector. row_vector = rot90(col_vector); #Convert a row vector to a column vector. col_vector = rot90(row_vector);