Labview and Matlab for PT

Just a place to discuss with Matlab and Labview

ad

整合程式終於出爐啦!!!!

這原本是我三年前剛畢業的時候想要完成的計畫,但是一直都沒有時間完成。這次一來剛好利用這次要分析數據的機會,二來因為之前分析的數據實在太多了,多到我都記不得有寫過哪些程式,分析過哪些數據,所以藉此機會除了把它整合在一起外,順便將實驗室過去用到的數據整理起來。

檔案下載:請按此 (密碼:同影印機)

以下為使用教學,我知道整個介面很醜,但是我實在很不喜歡修飾,等有空我再來修飾,功能可以用比較重要吧!


首先要先建立一個資料夾,這個程式的階層是這樣的:一個主要資料夾(這邊我舉例的主資料夾名稱為整合計畫test,裡面一定要自己設定一個叫data的資料夾),然後把同樣一隻腳的測試資料丟到data資料夾,這個程式會自動去尋找主資料夾裡的data資料夾,讀裡面的資料
 
   主資料夾
    - data
       - xxxx
       - xxxx
       - xxxx







然後在matlab的command視窗打入main_program(記得上面的current directory要改成剛剛下載好的檔案存放的路徑)。


接下來就出現選單,可以選擇要計算的參數(還真多啊!)。


這裡我就示範全部勾選,一口氣用這兩筆做ITT的資料跑出全部數據!


接下來會出現一個視窗(我知道真的很醜!),可以填寫姓名,左右腳,以及腳長,主要是在最後輸出檔案的時候上面可以註明這個資料的主人,但是這僅限於第一次用,因為這邊的功能以及資料的寫入都是用附加的方式,所以只有在第一次跑的時候因為檔案尚未存在而會寫入這些基本資料(我知道我解釋的很難懂!)。


選擇剛剛自己建立的主資料夾(此例就是整合計畫test),不要選到data資料夾!!




因為有些計算須要用到force onset,但是依我算了不算多的數據經驗發現,論文裡面所寫的用兩倍標準差當作開始根本就是一個理想,像我現在的例子就可以看到這個受試者居然在用力那瞬間力量突然往下掉(可能想利用stretch-shortening cycle的方式看可不可以力量大一點,所以先勾了一下),或者有些受試者在喊預備的時候就在那邊偷偷用力準備(這些不測風雲有時難以預測,有時候都不是當下可以發現到),所以這邊提供了輸了標準差的方式。




因為計算RFD以及RER須要換算成torque,所以都有勾選要計算這兩個參數的時候,就會出現要求輸入腳踝的長度(力臂)。




如果計算active EMD的話,會強迫重新輸入SD,至於原因則是不能說的秘密!




中間會出現一大堆運算後的圖片,這些都可以在之後主資料夾裡面找到(圖中為,百分比MVC對於時間的變化率)。


如果有勾選curveRMS這個參數(主要是計算不同百分比MVC下,EMG RMS對時間變化的斜率),會發現突然停頓,這是因為計算RMS所需的時間較長。


這邊也會要求輸入RMS EMG的SD,原因跟force一樣。


劈哩啪啦跑完之後,可以發現主資料夾多了很多資料夾,以及有一個叫做result.txt的檔案。


我們用一些文字編輯器或是notepad打開可以看到我們剛剛算的數據。


由於文字編輯器對於換格tab會因為字串長度不同可能無法對齊,導致看起來不是那麼好看,所以我們改用excel開啟看看。


由excel開啟之後,可以發現每個data都排排站站好。


而且每個參數都會把每次trial所計算的記錄下來(如果今天發生某次trial的值過於偏差,可以在此修改),以及這些trial的平均(有幾個檔案就用幾個平均,兩個檔案就兩個平均,三個就三個平均,一個當然就一個自己平均啦!真是太神奇啦!)!


然後我們打開資料夾看看,這邊是打開ITT資料夾,就可以看到這次所算的ITT圖以及結果。

當然如果要重算某樣參數也是可以,在不刪除result.txt的情況下,會自動把新算的數據直接附加到原來數據的最後,而資料夾裡面的圖片也自動被新的附蓋過去。當然如果想要重新跑的話,就把result.txt砍了就行了!

後記:

1. 這次的整合程式,主要的應用在我們做ITT的trial上面,也就是每次我都會跟受試者說要被電三次,我想如果都是照著這樣既定的protocol做的話,程式大多應該不會出現問題。

2. 我將原始檔案附在上面,希望大家使用上如果發生問題可以告知我(至少目前我的幾筆資料都是沒有問題),大家的反應才是可以把這個程式修改到好的原動力。

3. 這次有些程式我有改寫(變得比較精簡),然後整合程式撰寫我也是力求工整,這樣也比較利於之後如果有人想要增加新功能,新參數使用。

4. 有時間的話我再把他外觀弄得好看一點。

5. 最後,我該睡了!!

It takes me 3 years to figure out how to do DAQ in labview!!!!!

Hahaha!!! The title of this article is not real. Not until someone tell me the concept of shift register did I write labview since I began writing matlab. Today, I spent two hours to know how to do DAQ in labview which I didn't accomplish 3 years ago. The main reason possibly is that labview is my first programming language and I know nothing about programming, so it was difficult for me to do DAQ at that time.

Here is my simple code:



How to run matlab 7.1 on windows 7??

Recently, I have upgraded almost my computers to windows 7 except the computer in my lab. Yesterday, I installed matlab 7.1 on my desktop and found out some errors when running the program, even using the comparable mode provided by windows 7. So I find the solution on the internet and here is the solution.

The original article is from this: How To Run Matlab 7.1 On Windows 7



Instructions

  1. Right Click On Desktop, choose Personalize
  2. Got to Basic and High Contrast Themes tab, and click Window Classic
  3. Now, Run matlab
  4. Finish



So, if you want to use matlab 7.1 on windows 7, you need to accept the ugly theme when running matlab program. It's also a little bit inconvenient because you have to switch the theme when running Matlab.

ginput -- A Useful and Convenient Function


Yesterday night, one of junior classmates told me that he found a useful function called "ginput" which can make the thing getting mouse position easier than using "get(gca......)". It's very convenient when designing some program such as calculating angle in coordinate plane. So, here is a very simple example about how to calculate the angle in a certain image.

global flag h_im h_1
filename='D:\07020203_mpg2-0000281.jpg';
im=imread(filename);
h_im=image(im);
while 1
    cal_cord_ang;
end

function cal_cord_ang
global flag h_im h_1
cla(h_im)
[x,y] = ginput(1);
a=[x,y];
x0=a(1,1);
y0=a(1,2);
hold on
h_1=plot(x0,y0,'color','r','marker','+');
[x,y] = ginput(1);
b=[x,y];
x1=b(1,1);
y1=b(1,2);
h_1=plot([x0 x1],[y0 y1],'color','r','marker','+');
[x,y] = ginput(1);
c=[x,y];
x2=c(1,1);
y2=c(1,2);
h_1=plot([x0 x1 x2],[y0 y1 y2],'color','r','marker','+');

% calculate angle by using this formula --> A dot B = ABcos
A=a-b;
B=c-b;
angle=acosd(dot(A,B)/(norm(A)*norm(B)));
x_t=mean([x0 x2]);
y_t=mean([y0 y2]);
text(x_t,y_t,num2str(angle),'color','r')
ginput(1)
cla(h_im)

However, I almost forget the concept of vector, even the product of two vectors. You can review the concept in this url: http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm.

Try it, it's very funny!!!


[Transcripttion] 35 Complete GUI Examples

This article, 35 Complete GUI Examples, gives examples about GUI that I found today. It contains several questions that many people usually ask and also attaches the example codes. It is very useful reference when designing a GUI program.

Here is the description of this article:

The questions/files are written in approximate order of complexity, so intermediate users may want to skip the first several files. 
The questions answered include:

1. How do I manipulate the strings in a uicontrol? 
2. How do make a uicontrol invisible/visible?
 
3. How do I make a multi-line editbox?
 
4. How can I let the user of my GUI know his actions are futile (or producing no results)?
 
5. How can I tell which uicontrol is selected?
 
6. How can I tell how many times a uicontrol has been activated?
 
7. How do I tell which button in a buttongroup is selected?
 
8. How do I let the user know a process is running in the background?
 
9. How do I control the mouse pointer with a GUI?
 
10. How can I access the value (current position) of a slider?
 
11. How can I use different colored strings in a listbox?
 
12. What is the difference between 'listboxtop' and 'value' in a listbox?
 
13. How can I make text that can be copied but not changed?
 
14. How do I allow the user of my GUI to set the range of a slider?
 
15. How do I use the buttondownfcn on an axes object?
 
16. How do I make a callback talk to another callback?
 
17. How can I get the string from a popup or listbox?
 
18. How can I set the string in a popup or listbox?
 
19. How can I add to the string in a popup or listbox?
 
20. How do I tell which figure was current before my callback executed?
 
21. How do I get data from another GUI?
 
22. How do I make a GUI to open image files only?
 
23. How can I make popup choices mutually exclusive?
 
24. How can I show the current pointer location in axes coordinates?
 
25. How can I use uicontextmenus?
 
26. How do I make my GUI control an axes in another figure?
 
27. What are callback strings?
 
28. How can I make it so that when one of the figures closes, they all close?
 
29. How do I make several uicontrols interact in a more complicated GUI?
 
30. How do I get data from a GUI to the base workspace?
 
31. How do I make toggle buttons act like tabbed-panels?
 
32. How can I make a password editbox that has the ***** symbols?
 
33. How can I use nested function as callbacks?
 
34. How can I use uiwait in a GUI?
 
35. How do I use JAVA in my GUI?
 
36. How do I force the figure to maintain focus between uicontrol activations?
 
37. How do I save an axes as an image?
 
38. How can I make a simple drawing program?
 
39. How can I save the state of a system of GUIs to use later?

I am open to hearing any suggestion as to other questions which could be covered in the collection. Such suggestions need not be basic. Please read the pdf file prior to use. Also the contents.m file contains brief descriptions of each GUI.
Please email me if an error is found, either in the documentation or coding. Thanks.