(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 command clear and clc.
+
Start every MATLAB program with the commands clear and clc.
 +
<pre>
 +
# clear memory
 +
clear
  
clear - clear memory
+
# clear console
clc - clear console
+
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>
  
Read a wav file:
 
- [data, sample_rate, bits_per_sample] = wavread('c:\path\to\file\filename.wav');
 
  
Play the data from a wav file:
+
==== Reverse the data in a vector ====
- wavplay(data, sample_rate);
+
<pre>
- sound(data, sample_rate);
+
# Reverse a row vector
 +
row_vector = fliplr(row_vector);
  
Save a wav file:
+
# Reverse a column vector
- wavwrite(data,sample_rate,bits_per_sample,'/path/to/file/filename.wav');
+
col_vector = flipud(col_vector);
 +
</pre>
  
Reverse the data in a vector:
+
NOTE: The vector returned by wavread is a column vector. flipud must be used to reverse it.
flipud(row_vector)
+
fliplr(col_vector)
+
  
Convert a row vector to a column vector and vice versa:
+
 
row_vector = rot90(col_vector);
+
==== Convert a row vector to a column vector and vice versa ====
col_vector = rot90(row_vector);
+
<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

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

BSEE 2004, current Ph.D. student researching signal and image processing.

Landis Huffman