I have been wanting to figure this out for a long time, but have had no success yet. I am assuming I will use arrayfun, but I couldn't figure it yet. Appreciate help. Here is the problem:
Given a matrix of many rows and N^2 columns, reshape every row to NxN matrix and calculate eigenvalues, and do this in a vectorized way not using for loop. For example
A=
0.6060168 0.8340029 0.0064574 0.7133187
0.6325375 0.0919912 0.5692567 0.7432627
0.8292699 0.5136958 0.4171895 0.2530783
0.7966113 0.1975865 0.6687064 0.3226548
0.0163615 0.2123476 0.9868179 0.1478827
for every **i**
m=reshape(A(i,:),2,2)
[vc vl]=eig(m)
I am inclined to do something like
f = @(x) eig(reshape(x,2,2))
arrayfun(f,A)
but of course I am getting an error like
octave:5> arrayfun(f,A)
error: reshape: can't reshape 1x1 array to 2x2 array
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error: at line -1, column -1
error: cellfun: too many output arguments
error: /usr/share/octave/3.2.4/m/general/arrayfun.m at line 168, column 21