matlab memo 001: plot & display a photo

Lesson 1 The MATLAB Environment

clear
clc

plot

x_coordinates = [1,3,10];
y_coordinates = [2,4.2,12.3];
plot(x_coordinates,y_coordinates);
length(x_coordinates)
%plot each point separately
plot(x_coordinates,y_coordinates,'*');
%search documentation
doc plot
plot(x_coordinates,y_coordinates,'rs');
grid on
%add labels
xlabel('Selection')
ylabel('Change')
title('Changes in Selection during the Past Year')
%change the range of x & y
axis([0,12,-10,20])
%bar graph
bar(x_coordinates,y_coordinates)
%make a new figure window(/tab)
figure
%pie chart
pie([4 2 7 4 7])
%close the figure window two
close(2)
%close all figure windows
close all

display a photo

%a wrong way
imread('filename.jpg');
%a correct way
brainphoto=imread('wm_brain_regions.jpg');
image(brainphoto)
axis off

python勉強メモ: file

open(filename,mode)

  • mode(省略した時にrとして処理される)
    • w:write
    • r:read
  • テキストファイルを実行しようとするコードと同じフォルダーに置く
  • built-in functions

\n :newline 改行

改行もstringの1として数えられる

stuff="x\n y"

print stuff

x

y

len(stuff)

3

open a file, read every line in the file

xfile = open("mbox.txt")`

count = 0

for yomi in xfile:`

   count = count + 1
    print yomi`

print "line_count:", count

reading the whole file

we can read the whole file (newlines and all) into a sigle string

whole_file = xfile.read()

print whole_file

条件に合う行を探す

特定の文字で始まる行を探しだす

for sgashi in xfile:

    if sagashi.startwith("from:"):

        print sagashi

出力する時、自動的に改行が追加されるので、元々付いている改行符号を取り除かないと、空行ができてしまう。

空白(改行は空白だと認識される)を取り除く

for sgashi in xfile:

    sagashi = sagashi.rstrip()
 
    if sagashi.startwith("from:"):

        print sagashi
  • rstrip()
  • lstrip()
  • strip()

特定の文字の始まりではなければ、飛ばす

for sgashi in xfile:

    sagashi = sagashi.rstrip()
 
    if not sagashi.startwith("from:"):

        continue

     print sagashi

特定の文字を含む行を探す

for sgashi in xfile:

    sagashi = sagashi.rstrip()
 
    if not "@japan" in line:

        continue

     print sagashi

python勉強メモ: strings

  • string concatenation
  str1 = "hello"

  str2 = "mike"

  str3 =str1+str2

  print str3

実行結果: hellomike

+記号は文字列を繋げる。

  • raw_input()で取得したものは文字列になる。数字に変換するにはfloat()かint()を使う。

  • square brackets[]から文字列から一個ずつ文字を取り出せる。始まりは0だ。

  namae = "doreen"

  n = 2

  print namae[0]

d

  print namae[n]

r

  • len()は文字列の長さを数えてくれる。
  len(doreen)

6

  • looping through strings

    コード:

  namae = "doreen"
  
  for letter in namae:

      print letter

実行:  

d

o

r

e

e

n

  • slicing string

    • The second number is one beyond the end of the slice - “up to but not including”

    • If the second number is beyond the end of the string, it stops at the end.

    • If we leave off the first number or the last number of the slice, it is assumed to be the beginning or end of the string respectively

    コード:

  namae = "doreen python"
 
  print namae[0:1]

  print namae[2:4]

  print namae[5:8]

  print namae[8:20]

  print namae[8:]

  print namae[:3]

  print namae[:]

結果:

d

re

n p

ython

ython

dor

doreen python

  • string library

    • Python has a number of string functions which are in the string library.

    • These functions are already built into every string - we invoke them by appending the function to the string variable.

    • These functions do not modify the original string, instead they return a new string that has been altered.

    コード:

  namae = "DOREEN"

  print namae.lower()

結果:

doreen

 なお、dir(namae)で入力すれば、「namaeに対してどんなことができるの?」という質問をpythonにすることになる。

 pythonはこれに対して、使えるメソッドをすべて返してくれる。

 各functionの詳しい説明はhttps://docs.python.org/2/library/stdtypes.html#string-methodsを参照

  • find()

    • find() finds the first occurance of the substring

    • If the substring is not found, find() returns -1

    • Remeber that string position starts at zero

    コード:

  namae = "doreen"

  pos = namae.find("or")

  pos_b = namae.find("f")

  print pos

  print pos_b

結果:

1

-1 - upper()

コード:

  namae = "doreen"

  print namae.upper()

結果:

DOREEN

  • Searh and Replace

    • The replace() function is like a “search and replace” operation in a word processor

    • it replaces all occurrences of the search string with the placement string

    code:

  namae= "hello doreen"

  new_namae = namae.replace("doreen","dandelion")

  print new_namae

result:

hello dandelion

code:

  namae= "hello doreen"

  new_namae = namae.replace("e","E")

  print new_namae

result:

hEllo dorEEn

  • Stripping Whitespace

    • Sometimes we want to take a string and remove whitespace at the beginning and/or end

    • lstrip() and rstrip() to the left and right only

    • strip() removes both begin and ending whitespace

    code:

  namae= " hello doreen "

  namae.lstrip()

–>“hello doreen ”

  namae.rstrip()

–>“ hello doreen”

  namae.strip()

–>“hello doreen”

  • Prefixes

    code:

  line = "please have a nice day"

  line.startswith("please")

–>True

  line.startswith("P")

–>False

coursera python

try and except

  • you surround a dangerous section of code with try and except.
  • if the code in the try works- the except is skipped
  • if the code in the try fails- it jumps to the except section

is

  • Python has an “is” operator that can be used in logical expresstions
  • Implies is the same as
  • Similar to, but stronger than “==”
  • is not also is a logical operator
  • 一般的には使わない。TrueやFalseのような特殊な判断のみに使う。

python勉強メモ: Variables and Expressions

基礎の基礎の基礎

cd Desktopでデスクトップに行ける。

dirで所在位置のファイル一覧が見られる。

xyz.pyで直接プログラムを実行できる。

pythonの実行:

c:\python27\python

pythonからエグジット/を閉じる

quit()

データのタイプ:文字列or数値

  • string

    type(“a”)

    < type ‘str’ >

  • number

    int() integerへ変換

    注意:整数へ変換する際に、四捨五入は適用されない

    float() で小数点タイプへ変換

    int()或いはfloat()で文字列化された数値を数値化に戻せる

raw_input()

プログラム:

namae=raw_input(‘who are you?’)

print ‘welcome’,namae

‘doreen'で入力した際の実行結果:

who are you? doreen

welcome doreen

raw_input()で入力したものは文字列stringとして扱われる。

先行研究を読むときにわからないワード

resting-state functional connectivity (RSFC)

安静時 fMRI による運動関連領域間神経結合の解明 林 俊宏

通常の脳機能画像法では単なるベースラインとして扱わ れる安静時にも脳は活動を休止しているわけではない.安静 時の BOLD(blood oxygenation level-dependent)信号の低周 波性(0.1Hz 以下)のゆらぎ成分に着目すると,両側運動野の 信号に時間的相関関係があることを 1995 年に Biswal らが示 し,安静時の信号にも自発的脳活動に由来する機能的結合の 情報がふくまれていることが示唆された.この安静時の低周 波性ゆらぎ成分は信号自体が微弱であり,かつ呼吸・心拍な どの生理学的雑音も同周波数領域に混入しやすいなどの技術 的困難もあり,その応用はすぐには普及しなかった.2004 年に Greicius らがアルツハイマー病患者の安静時の fMRI に て健常対照群と比較して前頭葉内側面・頭頂葉内側面楔部 (default mode network)・海馬の機能的結合の低下を認めた との報告を契機に再度注目されるようになった.安静時のfMRI に よ る 機 能 的 結 合 の 評 価 は resting-state functional connectivity MRI(rs-fcMRI)とも呼ばれるようになり,様々 な神経・精神疾患を対象とした臨床研究もおこなわれつつある.ここで,従来の rs-fcMRI 研究は背側視覚系,腹側視覚系, 体性感覚・運動系, そして default mode network といった, 大域的神経ネットワークの活動をみるものが主であり,より 詳細な機能的結合の情報を抽出するのは困難であった.また rs-fcMRI で観察されるところの機能的結合の機序は解明さ れておらず,それらが実際の神経結合と合致するものかも不 明であった.演者はここ 10 年来おこなってきたサルをモデル 動物とした fMRI 方法論開発研究を基に,麻酔下サルでの rsfcMRI の方法論開発をおこなった.

Brain Connections – Resting State fMRI Functional Connectivity

ROIs

ROIの抽出方法

学術記事:Region of interest analysis for fMRI