Wednesday, November 28, 2012

MATLAB CODING - PART V

Matlab Database Connectivity Example code 

 1.Create Connection String

Connection String used to connect the database.That syntax as follows
conn_str = database('database_name','username','password','driver','database_url');
Example :
>>conn_str = database('my_db','scott','tiger','oracle.jdbc.driver.OracleDriver','jdbc:oracle:oci7:');


Here we create the connection string on Oracle database.Like you connect different type of  databases.

2.Execute Query String on Database

exec function to execute the query strings on database.Syntax as follows

curs = exec(conn_str, 'sql_query');

Example :

>>curs = exec(conn_str, 'Select * from My_Table');
 
 above example retrieve the all data's from My_Table.Like you do execute all type of sql queries.

3.Fetch the cursor to a MATLAB variable 

Here we convert the cursor data into matlab variable. example code as below

>>my_data = fetch(curs);

Finally my_data contain all data's of My_Table.
 

Matlab read raw file example code , Matlab convert raw file to Jpg example

 To convert raw file to Jpg image file example code.In raw file contain slices images . raw format is one of the image compress format.
code :

f=fopen('t1_icbm_normal_1mm_pn3_rf20.rawb');
a=fread(f);
input_img = reshape(a,181,217,181);
[r c m] = size(input_img);

for i = 1 : m
imwrite(input_img(:,:,i),['img_' num2str(i)],'jpg')
figure,imshow(uint8(input_img(:,:,i)));
end

In above code convert raw file to Jpg image file then write the image on current directory and show the each slice images.


No comments:

Post a Comment