Matlab (自分用覚え書き)

グラフの表示位置
rect=get(gcf,'Position')
figure('Position',rect)
 
2つのグラフを表示
yyaxis right  
 
X軸に平行な直線
line([X1 X2], [Y1 Y1]);
 
片対数
semilogy(Y)
 
両対数
loglog(X, Y)
 
ラベルを消す
set(gca, 'YTickLabel', [],'XTickLabel',[],'YTick',[],'XTick',[])
 
反転
set(gca, 'YDir','rev')
 
配列の一意の値の抽出
a=unique(A)
 
置換
A(A<0) = NaN;
A(A==0) =NaN;
 
行列の読み込み
fid=fopen('***','r');
%A=fgets(fid)
B=fscanf(fid,'%f', [72,36])
B=textscan(fid,'%s %d %d %f',[4, 500]); %s: 文字列
 
セル行列の保存
T=table(dat);
writetable(T, dirn4,'WriteVariableNames',false);
T=table(dat);
writetable(T, dirname,'WriteVariableNames',false);
 
NaNを無視した平均、中央値、分散
nanmean(x)
nanmedian(x)
nanstd(x)
 
figureをクリア
clf
figureを全て閉じる
close all force
 
ラベルのフォント・色
ylabel('***','Color','k','Fontname','Arial', 'FontSize', 12)
set(gca,'Xcolor',[0 0 0])
 
軸フォント
set(gca,'FontName','Arial','FontSize',10)
 
タイトル改行
title({'  ', '  '})
 
Emptyかどうかの判別
TF = isempty(A);  %Empty=1, else=0
 
排他的論理和集合
C=setxor(A, B);
共通集合
C=intersect(A, B);
 
ランダム置換
B=randperm(A);
 
文字列中の数値の判別
isstrprop('LT-W-100-1','digit')
 
文字列検索
k = strfind(str,'**')
 
 
カイ二乗逆累積分布関数
x2 = chi2inv(0.95,n) %自由度n
 
t 分布
t = tinv(0.95,n) %自由度n
 
2 標本 t 検定
h = ttest2(x,y)

 

正規累積分布関数

p=normcdf(2) % for 2 sigma

 

正規分布の標準偏差推定

[m,sig]=normfit(data);

 

Plot boxのアスペクト比

a=pbaspect; % plot box aspect ratio.

daspect([1 2 1]) % 設定 Data aspect ratio

 

2次元データの検索

[k1,k2,val]=find(data2d==x)

 

figureの保存

exportgraphics(gcf,'Figure1.png','Resolution',300)

exportgraphics(gcf,'Figure1.pdf','ContentType','vector')