vector input to function

조회 수: 2 (최근 30일)
Vesco
Vesco 2012년 12월 27일
Hi - this is a simple question, more about syntax.
I want to compute a function on a vector.
The function is the procrustes distance function which takes 2 nxm matrices.
procustes( nxm , nxm)
I want to compute it for a ND volume.
For example for a 3D volume
X = rand(2,3,5);
t = 1:5
d = procrustes(X(:,:,t),X(:,:,t));
hoping that d is a 1:5 vector
thanks

답변 (2개)

Wayne King
Wayne King 2012년 12월 27일
편집: Wayne King 2012년 12월 27일
Then you need to use a for loop and store the results
X = rand(2,3,5);
Y = randn(2,3,5);
for nn = 1:size(X,3)
d(nn) = procrustes(X(:,:,nn),Y(:,:,nn));
end
I'm assuming you actually meant to have a different matrix than X as the other input.
  댓글 수: 2
Vesco
Vesco 2012년 12월 27일
Thank you Wayne. I am currently using a for loop and yes the matrices are different. I was looking for a one-liner tho.
Jan
Jan 2012년 12월 28일
One-liners are more compact and therefore nicer, but not necessarily faster. When they are harder to create and to debug than an loop approach, it is questionable if they are useful.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2012년 12월 27일
d = arrayfun( @(K) procrustes( X(:,:,K), Y(:,:,K) ), 1 : size(X,3) );

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by