(3 intermediate revisions by the same user not shown)
Line 14: Line 14:
  
  
Start every MATLAB program with the command clear and clc.
+
Start every MATLAB program with the commands clear and clc.
 
<pre>
 
<pre>
 
# clear memory
 
# clear memory
Line 40: Line 40:
 
wavwrite(data,sample_rate,bits_per_sample,'/path/to/file/filename.wav');
 
wavwrite(data,sample_rate,bits_per_sample,'/path/to/file/filename.wav');
 
</pre>
 
</pre>
 +
 +
 
==== Reverse the data in a vector ====
 
==== Reverse the data in a vector ====
 
<pre>
 
<pre>
 
# Reverse a row vector
 
# Reverse a row vector
row_vector = flipud(row_vector);
+
row_vector = fliplr(row_vector);
  
 
# Reverse a column vector
 
# Reverse a column vector
col_vector = fliplr(col_vector);
+
col_vector = flipud(col_vector);
 
</pre>
 
</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 ====

Latest revision as of 07:14, 3 September 2008

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);

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang