星期四, 1月 11, 2007

MATLAB課堂作業: Finale

依據範例一所示之內容,請使用uicontrol指令自行寫出功能相同之M檔案:

程式內容:

function unicontrol_demo
% SIMPLE_GUI Select a data set from the pop-up menu, then% click one of the
% plot-type push buttons. Clicking the button
% plots the selected data in the axes.


f = figure('Visible','off','Position',[360,500,450,285]);
hbutton = uicontrol('Style','pushbutton','String','執行','Position',[350,330,100,40],'Callback',{@popup_menu_Callback});
hpopup = uicontrol('Style','popupmenu','String','plot(x)pie(x)hist(y)ezplot3(f)polar(theta,r)area(x,y)','Position',[170,335,150,25]);
htext = uicontrol('Style','text','String','請輸入繪圖指令:','Position',[60,335,100,25]);
hfigure = axes('Units','pixels','Position',[50,60,400,250]);

set(f,'Name','unicontrol_demo')
movegui(f,'center')
set(f,'Visible','on')
plot(rand(5));

function popup_menu_Callback(source,eventdata)
val = get(hpopup,'Value');
switch val;
case 1 % User selects plot(x).
plot(rand(5))
case 2 % User selects pie(x).
n = round(10*rand)+10;
pie(2:4:n);
case 3 % User selects hist(y).
hist(randn(1000,1));
case 4 % User selects ezplot3(f).
ezplot3('t*sin(t)', 'cos(t)', 't', [0,6*pi])
case 5 % User selects polar(theta,r).
theta = linspace(0, 2*pi);
polar(theta, 3+2*rand*cos(4*theta));
case 6 % User selects area(x,y).
y=[1 1.2 1.5 2*rand;4 4.5 6.6 7*rand;5 6.5 8 15*rand]';
area([1980 1990 2000 2008],y);
grid on;colormap cool;
end
end
end

執行結果:
plot                                        pie

historgram                                  ezplot3

polar                                       area

星期四, 1月 04, 2007

Topic: 人體受外力牽拉後引發之姿勢反應_肌肉活化情形_finale



(Horak et al., 1992)













前言:
當人體在站立姿勢下接受一外在的平衡干擾時,下肢與軀幹肌肉的活化程度可以反映人體受到外在干擾後引發之姿勢反應。而當人體在站姿下受到外力干擾而產生前向的身體擺盪時,背側的肌肉主要負責活化以維持或回復平衡,避免跌倒發生。過去文獻指出,當站立於一塊會產生水平後向移動之力板上時,隨著干擾強度增加(力板移動速度加快或移動位移增加),受試者肌肉活化程度亦會隨之增加。但,由腳底板所接受之干擾與從腰間承受之外在干擾對於受試者的姿勢干擾程度與形式是有所不同的,因此,當受試者由腰間接受干擾後,其肌肉活化情形是否亦會隨著干擾強度增加而增加則值得探討。


實驗目的:
探討人體在站姿下從腰部位置受到之前向牽拉干擾時背側肌肉之活化情形,且比較在不同牽拉強度干擾下,人體反應是否會隨之變化。



實驗流程:
在受試者肚臍位置穿戴一腰帶,將三牽拉軸之牽拉線固定於受試者腰帶上(如上圖),由三牽拉軸產生之合力提供為干擾受試者站立平衡之牽拉力量。受試者在受到牽拉之後必須在不跨步的前提下盡可能地維持平衡不跌倒。牽拉強度共有4種 (固定牽拉速度為9cm/s,牽拉位移則依序增加:3,5,7,9cm),每個牽拉強度情境各進行3次測試。以肌電圖所量測到的肌肉活化情形作為受試者受牽拉後的姿勢反應依據,受測肌肉包括:腓腸肌 (MG)、膕旁肌(HAM)、臀中肌(GM),以及脊旁肌(PARA)。



牽拉位移 (cm)牽拉速度 (cm/s)
V139
V259
V379
V499


MATLAB程式目的:
由既訂之檔案途徑擷取資料:一為原始檔案(包括時間與肌肉活化大小(以voltage表示)),一為選取後之onset時間(牽拉開始以及各肌肉開始活化時間)。

功能一(mode 1):
(1) 同時計算各個受試者在不同牽拉強度所引發之integral EMG大小,IEMG計算方式為"肌肉開始活化後150~500毫秒減去牽拉開始前150~500毫秒時間內之IEMG大小做標準化"(總共12次測試)。並計算各個牽拉強度下各受測肌肉IEMG之平均值與標準差(共分為四個強度),以.xls檔案形式儲存於特定資料夾中。
(2) Missing data的處理
a. 當原始EMG資料中任一塊肌肉訊號有所遺漏時,其計算出來的IEMG數值會以NaN顯示,程式可判斷'如果同一次測試中,有任一塊肌肉IEMG數值缺乏時,則該次測試所有肌肉的IEMG數值以-99表示,且皆不列入最後的平均值與標準差之計算'。
b. 另外,程式亦可判斷'當某次測試的原始EMG資料檔案不存在時,則該次測試所有肌肉的IEMG數值以-99表示,且皆不列入最後的平均值與標準差之計算'。
(3) 計算所有受試者在各個牽拉強度下IEMG數值之平均值(group mean),以繪出牽拉強度與肌肉反應之關係圖,並將圖形儲存於特定資料夾中。

功能二(mode 2):畫出各個牽拉強度下EMG活化情形(各以其中一個具代表性的trial呈現),並儲存於既定之資料夾內。

Flowchart


程式內容:
% IEMG7.m
% function: IEMG calculation (including mean and std of the value of each perturbation amplitude) for all trials of each subject
% onset data were retrived automatically
% if the file of raw data is not existed or the data of the measurments of a trial is not recorded, print all the IEMG data of that trial '-99'
% the IEMG results were output and saved as .xls
% print out figures of the selected trials and saved as .jpg
% raw_data: 1_Time(ms) 2_Fy 3_Mx 4_MGr 5_HAMr 6_PARAr 7_GMr 8_Pullonset
% range from (600ms prior to the pull onset) to (5000ms after the pull onset)
% baseline EMG:time interval between (500ms prior to the pull onset) to (150ms priot to the pull onset)
% IEMG:time interval between (150ms after the burst onset) to (500ms after the burst onset)

fclose('all');
clear all;
clc;
global EMGdata_path;
EMGdata_path = input('Please input the folder of the EMG data: [e.g.: D:\\Physical Therapy\\Graduate School\\Thesis\\Pilot study for Thesis\\Data\\Processed data for Matlab]','s');

if isempty(EMGdata_path)
EMGdata_path = 'D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Data\Processed data for Matlab';
end

cd(EMGdata_path);
Subject_information = textread('Subject_information.txt','%s');
Subject_amount = size(Subject_information,1);
EMGfig_information = textread('EMGfig_information.txt','%s');
EMGfig_amount = size(EMGfig_information,1);

EMGoutput_path = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab'];
if ~exist(EMGoutput_path,'dir')
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab');
end

mod_choice = input('Please Choose the Mode: [1] Integrated EMG Analysis and Correlation Figure Print-out. [2] EMG Figure Print-out. [e.g. 1 or 2]');

switch mod_choice
case 1
for i = 1:Subject_amount
subjectoutput_folder = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab\Results for IEMG calculation'];
if ~exist(subjectoutput_folder,'dir')
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab\Results for IEMG calculation');
end

Onsetdata_xls = xlsread([EMGdata_path,'\',Subject_information{i}(1:4),'\','Time events for EMG and pullonset signials.xls'],'B3:F14'); % [pullonset,MGronset,HAMronset,PARAronset,GMronset]

data_name=0;
Onsetdata=0;
IEMG=0;

fprintf('\n %s\t\t rMG (V*ms)\t rHAM (V*ms)\t rPARA (V*ms)\t rGM (V*ms)\n',Subject_information{i}(1:4))

IEMG_fid = fopen([subjectoutput_folder,'\',Subject_information{i},'Integrated EMG','.xls'],'w');
fprintf(IEMG_fid,' \t rMG (V*ms)\t rHAM (V*ms)\t rPARA (V*ms)\t rGM (V*ms)\n');

for j = 1:4 % 4 perturbation amplitudes
for k = 1:3 % 3 trials
data_name = [Subject_information{i}(1:4),'C',num2str(1),'V',num2str(j),'R',num2str(k)];
Onsetdata = Onsetdata_xls((j-1)*3+k,:);
rawdata_file = [EMGdata_path,'\',Subject_information{i}(1:4),'\',data_name,'.xls'];
if exist(rawdata_file)
raw_data = xlsread([EMGdata_path,'\',Subject_information{i}(1:4),'\',data_name,'.xls'],'C19:J5618');
baseline = mean(raw_data(101:451,4:7));

rawIEMG(1) = (1/2*(raw_data((Onsetdata(2)-Onsetdata(1)+749),4)+raw_data((Onsetdata(2)-Onsetdata(1)+1099),4))+sum(raw_data((Onsetdata(2)-Onsetdata(1)+750):(Onsetdata(2)-Onsetdata(1)+1098),4))); % unit:V*ms
rawIEMG(2) = (1/2*(raw_data((Onsetdata(3)-Onsetdata(1)+749),5)+raw_data((Onsetdata(3)-Onsetdata(1)+1099),5))+sum(raw_data((Onsetdata(3)-Onsetdata(1)+750):(Onsetdata(3)-Onsetdata(1)+1098),5))); % unit:V*ms
rawIEMG(3) = (1/2*(raw_data((Onsetdata(4)-Onsetdata(1)+749),6)+raw_data((Onsetdata(4)-Onsetdata(1)+1099),6))+sum(raw_data((Onsetdata(4)-Onsetdata(1)+750):(Onsetdata(4)-Onsetdata(1)+1098),6))); % unit:V*ms
rawIEMG(4) = (1/2*(raw_data((Onsetdata(5)-Onsetdata(1)+749),7)+raw_data((Onsetdata(5)-Onsetdata(1)+1099),7))+sum(raw_data((Onsetdata(5)-Onsetdata(1)+750):(Onsetdata(5)-Onsetdata(1)+1098),7))); % unit:V*ms

IEMG = rawIEMG-baseline; % [rMG rHAM rPARA rGM]
if ~isempty(find(isnan(IEMG)))
IEMG(1,1:4) = -99;
end
else
IEMG(1,1:4) = -99;
end

IEMG_command = ['IEMG_cell(',num2str(k),',:) ={IEMG};'];
eval(IEMG_command)

fprintf(' %s\t %f\t %f\t %f\t %f\n',data_name,IEMG)

fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n',data_name,IEMG);
end % for k loop

IEMG_array = reshape([IEMG_cell{:}],4,3)';
for l = 1:4
if ~isempty((find(IEMG_array(:,l) ~= -99)))
mean_IEMG(1,l) = mean(IEMG_array(find(IEMG_array(:,l) ~= -99),l));
std_IEMG(1,l) = std(IEMG_array(find(IEMG_array(:,l) ~= -99),l));
else
mean_IEMG(1,1:4) = -99;
std_IEMG(1,1:4) = -99;
end
end

fprintf(IEMG_fid,' \n');
fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n','Mean',mean_IEMG);
fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n','Std',std_IEMG);
fprintf(IEMG_fid,' \n');

IEMGmean_command = ['IEMGmean_cell(',num2str(j),',:) ={mean_IEMG};'];
eval(IEMGmean_command)

end % for j loop

IEMGmean_array(:,:,i) = reshape([IEMGmean_cell{:}],4,4)';
for q = 1:4 % 4 perturbation amplitudes
sumEMG(q) = sum(IEMGmean_array(q,1,1:i));
GroupMean_cell{1} = sumEMG./Subject_amount;
end
for q = 1:4 % 4 perturbation amplitudes
sumEMG(q) = sum(IEMGmean_array(q,2,1:i));
GroupMean_cell{2} = sumEMG./Subject_amount;
end
for q = 1:4 % 4 perturbation amplitudes
sumEMG(q) = sum(IEMGmean_array(q,3,1:i));
GroupMean_cell{3} = sumEMG./Subject_amount;
end
for q = 1:4 % 4 perturbation amplitudes
sumEMG(q) = sum(IEMGmean_array(q,4,1:i));
GroupMean_cell{4} = sumEMG./Subject_amount;
end

fclose(IEMG_fid);
end % for i loop

GroupMean = reshape([GroupMean_cell{:}],4,4);
x = 1:4;
amp = ['V1';'V2';'V3';'V4'];
cor_IEMG = plot(x,GroupMean,'linewidth',2);xlabel('Perturbation cnodition');ylabel('Mean IEMG (V*ms)');title('Correaltion between muscle responses and perturbation amplitude');legend('MG','HAM','PARA','GM');box off;
set(gca,'xtick',1:4,'xticklabel',amp);
saveas(gcf,'D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab\Results for IEMG calculation\IEMGScalingFig','jpg')

case 2
for m = 1:EMGfig_amount
Onsetdata_xls = xlsread([EMGdata_path,'\',EMGfig_information{m}(1:4),'\','Time events for EMG and pullonset signials.xls'],'B3:F14'); % [pullonset,MGronset,HAMronset,PARAronset,GMronset]
data_name = [EMGfig_information{m}(1:10)];
Onsetdata = Onsetdata_xls((str2num(EMGfig_information{m}(8))-1)*3+str2num(EMGfig_information{m}(10)),:);
raw_data = xlsread([EMGdata_path,'\',EMGfig_information{m}(1:4),'\',data_name,'.xls'],'C19:J5618');

muscle_name = {'MG (V)' 'HAM (V)' 'PARA (V)' 'GM (V)'};
linecolor = ['b' 'r' 'g' 'm'];
for n=1:4
subplot(4,1,n),fig_EMG = plot((raw_data(:,1)),(raw_data(:,n+3)),linecolor(n));xlabel('Time (ms)');box off;hold on;onsetline=plot(Onsetdata(1)*ones(100,1),0:max(raw_data(:,n+3))/99:max(raw_data(:,n+3)),'k');text(Onsetdata(1),max(raw_data(:,n+3)),'pull onset');
ylabel_command = ['ylabel(''',muscle_name{n},''')'];
eval(ylabel_command)
end % for n loop

subjectoutput_folder = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab\EMG figures'];
if ~exist(subjectoutput_folder,'dir')
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab\EMG figures');
end

IEMG_fig_command = ['saveas(gcf,''D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab\EMG figures\',data_name,'_fig'',','''jpg'')'];
eval(IEMG_fig_command)
clf;

fprintf('figure print-out: %s\n',data_name)

end % for m loop
end
raw_path = 'C:\MATLAB701\work';
cd(raw_path);

執行結果:

IEMG數值 (以He01為例)
   
rMG (V*ms) rHAM (V*ms) rPARA (V*ms) rGM (V*ms)
He01C1V1R1 2.356 2.288 1.054 5.551
He01C1V1R2 1.641 2.368 0.907 5.878
He01C1V1R3 2.089 2.423 0.927 5.477

Mean 2.029 2.36 0.963 5.636
Std 0.361 0.068 0.08 0.213

He01C1V2R1 2.072 1.916 1.222 5.586
He01C1V2R2 1.198 1.862 1.34 5.578
He01C1V2R3 2.608 1.998 1.614 5.718

Mean 1.959 1.926 1.392 5.627
Std 0.712 0.068 0.201 0.078

He01C1V3R1 2.816 2.233 0.766 5.599
He01C1V3R2 1.951 1.883 3.109 5.227
He01C1V3R3 2.678 2.139 1.792 5.382

Mean 2.482 2.085 1.889 5.403
Std 0.465 0.181 1.175 0.187

He01C1V4R1 2.252 2.067 2.343 5.017
He01C1V4R2 1.52 2.334 0.745 2.722
He01C1V4R3 1.588 1.777 0.967 4.878

Mean 1.787 2.059 1.352 4.206
Std 0.404 0.279 0.866 1.287

牽拉強度與肌肉反應之關係圖


EMG圖形

星期四, 12月 28, 2006

Topic: 人體受外力牽拉後引發之姿勢反應_肌肉活化情形_rev.2

程式更新描述:
1. 加入各個牽拉強度下3次測試IEMG平均值及標準差計算,並將每位受試者各個測試以及各個牽拉強度(平均值與標準差)的IEMG計算結果輸出於同一檔案中,並以.xls檔案形式儲存於特定資料夾中。
2. Missing data的處理
(1)當原始EMG資料中任一塊肌肉訊號有所遺漏時,其計算出來的IEMG數值會以NaN顯示,程式可判斷'如果同一次測試中,有任一塊肌肉IEMG數值缺乏時,則該次測試所有肌肉的IEMG數值以-99表示,且皆不列入最後的平均值與標準差之計算'。
(2)另外,程式亦可判斷'當某次測試的原始EMG資料檔案不存在時,則該次測試所有肌肉的IEMG數值以-99表示,且皆不列入最後的平均值與標準差之計算'。

程式內容:

% IEMG6.m
% function: IEMG calculation (including mean and std of the value of each
% perturbation amplitude) for all trials of each subject
% onset data were retrived automatically
% if the file of raw data is not existed or the data of the measurments of a trial is not recorded, print all the IEMG data of that trial '-99'
% the IEMG results were output and saved as .xls
% raw_data: 1_Time(ms) 2_Fy 3_Mx 4_MGr 5_HAMr 6_PARAr 7_GMr 8_Pullonset
% range from (600ms prior to the pull onset) to (5000ms after the pull
% onset)
% baseline EMG:time interval between (500ms prior to the pull onset) to (150ms priot to the pull onset)
% IEMG:time interval between (150ms after the burst onset) to (500ms after the burst onset)

global EMGdata_path;
EMGdata_path = input('Please input the folder of the EMG data: [e.g.: D:\\Physical Therapy\\Graduate School\\Thesis\\Pilot study for Thesis\\Data\\Processed data for Matlab]','s');

if isempty(EMGdata_path)
EMGdata_path = 'D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Data\Processed data for Matlab';
end

cd(EMGdata_path);
Subject_information = textread('Subject_information.txt','%s');
Subject_amount = size(Subject_information,1);

EMGoutput_path = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab'];
if ~exist(EMGoutput_path,'dir')
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab'); % creates the directory dirname in the current directory, if dirname represents a relative path.
end

for i = 1:Subject_amount

subjectoutput_folder = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab','\',Subject_information{i}];
if ~exist(subjectoutput_folder,'dir') % dir 顯示目前目錄下的檔案名稱
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab',Subject_information{i});
end

Onsetdata_xls = xlsread([EMGdata_path,'\',Subject_information{i}(1:4),'\','Time events for EMG and pullonset signials.xls'],'B3:F14'); % [pullonset,MGronset,HAMronset,PARAronset,GMronset]

data_name=0;
Onsetdata=0;
IEMG=0;

fprintf('\n %s\t\t rMG (V*ms)\t rHAM (V*ms)\t rPARA (V*ms)\t rGM (V*ms)\n',Subject_information{i}(1:4))

IEMG_fid = fopen([subjectoutput_folder,'\',Subject_information{i},'Integrated EMG','.xls'],'w');
fprintf(IEMG_fid,' \t rMG (V*ms)\t rHAM (V*ms)\t rPARA (V*ms)\t rGM (V*ms)\n');

for j = 1:4 % 4 perturbation amplitudes
for k = 1:3 % 3 trials
data_name = [Subject_information{i}(1:4),'C',num2str(1),'V',num2str(j),'R',num2str(k)];
Onsetdata = Onsetdata_xls((j-1)*3+k,:);
rawdata_file = [EMGdata_path,'\',Subject_information{i}(1:4),'\',data_name,'.xls'];
if exist(rawdata_file)
raw_data = xlsread([EMGdata_path,'\',Subject_information{i}(1:4),'\',data_name,'.xls'],'C19:J5618');
baseline = mean(raw_data(101:451,4:7));

rawIEMG(1) = (1/2*(raw_data((Onsetdata(2)-Onsetdata(1)+149),4)+raw_data((Onsetdata(2)-Onsetdata(1)+499),4))+sum(raw_data((Onsetdata(2)-Onsetdata(1)+150):(Onsetdata(2)-Onsetdata(1)+498),4))); % unit:V*ms
rawIEMG(2) = (1/2*(raw_data((Onsetdata(3)-Onsetdata(1)+149),5)+raw_data((Onsetdata(3)-Onsetdata(1)+499),5))+sum(raw_data((Onsetdata(3)-Onsetdata(1)+150):(Onsetdata(3)-Onsetdata(1)+498),5))); % unit:V*ms
rawIEMG(3) = (1/2*(raw_data((Onsetdata(4)-Onsetdata(1)+149),6)+raw_data((Onsetdata(4)-Onsetdata(1)+499),6))+sum(raw_data((Onsetdata(4)-Onsetdata(1)+150):(Onsetdata(4)-Onsetdata(1)+498),6))); % unit:V*ms
rawIEMG(4) = (1/2*(raw_data((Onsetdata(5)-Onsetdata(1)+149),7)+raw_data((Onsetdata(5)-Onsetdata(1)+499),7))+sum(raw_data((Onsetdata(5)-Onsetdata(1)+150):(Onsetdata(5)-Onsetdata(1)+498),7))); % unit:V*ms

IEMG = rawIEMG-baseline; % [rMG rHAM rPARA rGM]
if ~isempty(find(isnan(IEMG))) % 如果有其中一個參數出現missing,則那一個trial內所有的參數皆不列入最後的平均計算
IEMG(1,1:4) = -99;
end
else
IEMG(1,1:4) = -99;
end

IEMG_command = ['IEMG_cell(',num2str(k),',:) ={IEMG};'];
eval(IEMG_command)

fprintf(' %s\t %f\t %f\t %f\t %f\n',data_name,IEMG)

fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n',data_name,IEMG);
end % for k loop

IEMG_array = reshape([IEMG_cell{:}],4,3)';
for l = 1:4
if ~isempty((find(IEMG_array(:,l) ~= -99)))
mean_IEMG(1,l) = mean(IEMG_array(find(IEMG_array(:,l) ~= -99),l));
std_IEMG(1,l) = std(IEMG_array(find(IEMG_array(:,l) ~= -99),l));
else
mean_IEMG(1,1:4) = -99;
std_IEMG(1,1:4) = -99;
end
end

fprintf(IEMG_fid,' \n');
fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n','Mean',mean_IEMG);
fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n','Std',std_IEMG);
fprintf(IEMG_fid,' \n');
end % for j loop

fclose(IEMG_fid);

end % for i loop

討論:
待完成事項:
1. 將程式一開始改為3種mode選擇:mode1-計算IEMG;mode2-單純繪出代表的EMG圖形;mode3-計算肌肉活化程度(IEMG)與干擾強度之相關性並繪圖。

星期六, 12月 23, 2006

Blog 小程式相關網站

@ 計時器

※ ClockLink
http://www.clocklink.com/
有各種不同分類的計時器,不過相較於日本人做的版本就有點死板的感覺

※ブログパーツの森
http://www.blogpartsnomori.com/
提供不同款式的小熊造型時鐘,超可愛 ><

※ポストペットブログアクセサリ(PostPet Blog Accessory) http://www.postpet.so-net.ne.jp/webmail/blog/ 多款造型可愛的寵物小時鐘,現在網頁上的企鵝計時器就是從這裡找到的喔....

@ 另類小程式

※ Moon Phases
http://www.calculatorcat.com/moon_phases/moon_phases.phtml
能夠知道現在月亮的陰晴圓缺喔....

@ 提供多種Blog小程式

※ Blog Apartments
http://blog-apart.com/index.html
分為三大類:Utility Blog Parts、Game Blog Parts,還有Interactive Blog Parts

※ブログパーツ.com
http://www.blog-parts.com/
分成十六個項目,包括計時器、溫度計、占卜、天氣預報等小程式。有些需要先登錄才能下載喔。

星期四, 12月 21, 2006

matlab課堂筆記 061222_第十一章 統計與迴歸

相關係數 corrcoef

R = corrcoef(X)
R = corrcoef(x,y)
[R,P]=corrcoef(...)


R代表correlation coefficient;P即代表判斷是否有統計意義的p

例題:
>> x=1:5;y=x.^3;
>> [R,P]=corrcoef(x,y)

R =
1.0000 0.9431
0.9431 1.0000
P =
1.0000 0.0161
0.0161 1.0000
>> [i,j] = find(P<0.05)

i =
2
1
j =
1
2

R(1,1)代表x和x之間的相關係數 → 一定為1
R(2,1)代表y和x之間的相關係數 → 一定為1
R(1,2)代表x和y之間的相關係數
R(2,2)代表y和y之間的相關係數


群組函數 grpstats

應用於計算複雜分組的平均問題。

means = grpstats(X, group)
[means, sem, counts, name] = grpstats(X, group, whichstats)
grpstats(x, group, alpha)


輸入參數中X為求平均值之對象(可為多行,其平均結果也會多行)。group則為與X同列長之陣列,可能由多項分組之向量組成,其內容可為字串列或細胞陣列之文字,如{G1 G2 G3}。在輸出項中,第一項means為群組平均,sem為組內標準差,counts為各組之項數,name則為各組之名稱。

例題:
x =
1 2 3 4 5 6 7 8 9
>> group=[1 1 1 1 2 2 2 2 2]
group =
1 1 1 1 2 2 2 2 2
>> [m,s,c]=grpstats(x,group)
m =
2.5000
7.0000
s =
0.6455
0.7071
c =
4
5

特殊指令 normrnd

normrnd(m,s)

可由一個平均值為m,標準差為s的平均分佈中隨機產生一個數值。

堆疊矩陣 repmat

B = repmat(A,m,n)
B = repmat(A,[m n])
B = repmat(A,[m n p...])


以A之內容堆疊在一(M x N)的矩陣B中。B矩陣之大小由MXN及A矩陣之內容決定。

例題:可以repmat指令作出與ones(3,3)*5相同的結果
>> repmat(5,3,3)

ans =

5 5 5
5 5 5
5 5 5

和使用ones(m,m)*n的方式相比的優點是
使用repmat指令可以在A置放文字串!!!