size()

  會傳回一個矩陣的row and column,若是圖片則會傳回3個值,

  分別為row , column , RGB.

  其中RGB分為1,2,3分別代表red,green以及blue.

abs()

  傳回計算後的絕對值

 

讀取txt中的檔案

假設txt中為:

abcde

cdefg

指令:    

out = textread('filename','%s');  //其中%s表示讀取進來的格式 , %s表示string

( 但是這樣的做法, 出來的字串會有單引號 ,無法做為image read所需的字串);

改良方法 :

以fr = fopen('filename','r');進行讀取   //fw =fileopen('filename','w')可進行write的動作.

   file_location = fgetl(fr) ; // 可以每次讀取進來一個line.

   im=image(file_location) ;

  便可將image的內容讀取進來. 

 

Writing the content to txt file

1.首先必須要先進行file open

2.以fprintf ('file name' , 'format' , e1,e2);  //其中e1 , e2 代表我們要寫入的內容.

Example :

fw=fopen('filename','w');

fprintf('database.txt','%s','string') ;  //%s代表要寫入的內容為String.

ref:http://www.mathworks.com/help/techdoc/ref/fprintf.html

由file holder中讀取file name

要讀取file name ,可用dir指令 ,讀取進來之後為struct的資料結構

其Struct為 :

name

File or folder name

char array

date

Modification date timestamp

char array

bytes

Size of the file in bytes

double

isdir

1 if name is a folder; 0 if not

logical

datenum

Modification date as serial date number. The value is locale-dependent.

double

Example :

list = dir ('holder name');

list(1).name;   // 會output在struct中的name ,attention:在matlab中的index是從1開始

 

String 連結

在matlab中 ,string的連結很簡單,

Example:

a='string1';

b='string2';

c=[a,b];   //此時c is 'string1string2'

 

Matlab function reference

http://www.math.ufl.edu/help/matlab-tutorial/matlab-tutorial.html

 

將cell中的string變量 ,轉換為string

不管是使用textread 或是藉由getl來將string除到cell中,

此時由cell中所調用的string並非是真的string ,而是 cell中的一個變量.

Example:

cell{1}(1) = 'string'

這個變量並無法像real string  來做使用,

所以我們必須將他由cell的變量轉換為string ,

方法如下:

b=cell{1}(1);

b=b{1};   //此時b{1}就是string ,所以我們只要將b{1} 再assign給b ,就可得到real string.

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JerryCheng 的頭像
    JerryCheng

    KwCheng's blog

    JerryCheng 發表在 痞客邦 留言(0) 人氣()