vector input to function
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Wayne King
on 27 Dec 2012
Edited: Wayne King
on 27 Dec 2012
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 Comments
Jan
on 28 Dec 2012
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
on 27 Dec 2012
d = arrayfun( @(K) procrustes( X(:,:,K), Y(:,:,K) ), 1 : size(X,3) );
0 Comments
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!