Just My Life & My Work

Archive for 2011 年 03 月 17 日

[C++] 指標的藝術 (Art of Pointer)

之前以為指標有限制【深度】,
在看過了「指標的藝術」這本書後,
馬上來測試指標深度的極限,
我驗證到10層都還可以編譯,
相信若compiler沒有限制的話,
是可以到【無限】深度的!
不過倒是沒看過有人會寫超過2顆*的程式,
人類的理解程度最多可到3維也就是3顆*,
【空間概念】厲害的人就可以玩弄星星於鼓掌之中XD~
有興趣的人可以玩一玩喔~

/**
	Theme: Art of Pointer
	Date: 100/01/25
	compiler: Dev C++ 4.9.9.2
	Author: ShengWen
	Blog: https://cg2010studio.wordpress.com/
*/
#include<iostream>
using namespace std;

int main(){
	int number=99;
	int *onePointer;
	int **twoPointer;
	int ***threePointer;
	int ****fourPointer;
	int *****fivePointer;
	int ******sixPointer;
	int *******sevenPointer;
	int ********eightPointer;
	int *********ninePointer;
	int **********tenPointer;

	onePointer=&number;
	twoPointer=&onePointer;
	threePointer=&twoPointer;
	fourPointer=&threePointer;
	fivePointer=&fourPointer;
	sixPointer=&fivePointer;
	sevenPointer=&sixPointer;
	eightPointer=&sevenPointer;
	ninePointer=&eightPointer;
	tenPointer=&ninePointer;

	cout<<&tenPointer<<endl;
	cout<<tenPointer<<endl;
	cout<<*tenPointer<<endl;
	cout<<**tenPointer<<endl;
	cout<<***tenPointer<<endl;
	cout<<****tenPointer<<endl;
	cout<<*****tenPointer<<endl;
	cout<<******tenPointer<<endl;
	cout<<*******tenPointer<<endl;
	cout<<********tenPointer<<endl;
	cout<<*********tenPointer<<endl;
	cout<<**********tenPointer<<endl;
	system("pause");
	return EXIT_SUCCESS;
}

輸出結果:

0x23ff4c
0x23ff50
0x23ff54
0x23ff58
0x23ff5c
0x23ff60
0x23ff64
0x23ff68
0x23ff6c
0x23ff70
0x23ff74
99
請按任意鍵繼續 . . .

[MatLab] 馬氏距離的理論與實做 (Mahalanobis Distance)

總算知道【馬氏距離】的意義,
加上實際操作MATLAB來驗證理論,
真正瞭然於心。
話說MATLAB真是一個強大的工具呢!

Mahalanobis distance

From WiKi (http://en.wikipedia.org/wiki/Mahalanobis_distance)

In statistics, Mahalanobis distance is a distance measure introduced by P. C. Mahalanobis in 1936. It is based on correlations between variables by which different patterns can be identified and analyzed. It is a useful way of determining similarity of an unknown sample set to a known one. It differs from Euclidean distance in that it takes into account the correlations of the data set and is scale-invariant. In other words, it is a multivariate effect size.

Definition

Formally, the Mahalanobis distance of a multivariate vector from a group of values with mean and covariance matrix S is defined as:

(繼續閱讀…)

標籤雲