LoginSignup
7

More than 5 years have passed since last update.

[matlab] 生産性をバク上げするライブラリ[Yaml]

Last updated at Posted at 2015-07-03

intro

昨日、生産性をバク上げするライブラリを発見したので報告します。

YamlMatlab

ruby界隈とか、js界隈ではyamlを設定ファイルに使うと思うんですけど、
これがmatlabでも利用可能になるっていうシロモノです。

実装例

例えば、

const.m
function ret = const(group)
  % litrconst: return literal constants
  % litr = litrconst().ja;
  % litr.ordinal{1}
  if nargin == 0, group = ''; end
  switch group
    case 'env'
      ret = ReadYaml('src/envconst.yaml');
    case 'litr'
      ret = ReadYaml('src/litrconst.yaml');
    otherwise
      ret = ReadYaml('src/litrconst.yaml');
  end
end
src/litrconst.yaml
ja:
  ordinal:
    - 第1
    - 第2
    - 第3
    - 第4
    - 第5
    - 第6
    - 第7
    - 第8
    - 第9
    - 第10
  principlecomp: 主成分
  percent: 
en:
  ordinal:
    - 1st
    - 2nd
    - 3rd
    - 4th
    - 5th
    - 6th
    - 7th
    - 8th
    - 9th
    - 10th
  principlecomp: Principal Component
  percent: 
envconst.yaml
datadir: \data\
resultdir: \results\

などと作ると、

>> litr = const().ja
litr = 
          ordinal: {'第1'  '第2'  '第3'  '第4'  '第5'  '第6'  '第7'  '第8'  '第9'  '第10'}
    principlecomp: '主成分'
          percent: '%'
>> litr.ordinal{3}
ans =
第3
>> env = const('env')
env = 
      datadir: '\data\'
    resultdir: '\results\'
>> env.datadir
ans =
\data\

とかってできるわけですよ。
煩雑にいちいち文字列をタイプしていたのが
autocompleteで済んだりするのでとてもオススメです。
解析現場からは以上です。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7