i wondering how arrange input parameters of mode function in order calculate matrix of modes input 2d matrices in 1 line of code..
for example
x=[7 2;5 10] y=[7 1;8 3 ] z=[7 2;8 10]
i want mode(x,y,z) gives output
output=[7 2;8 10] // these occurring elements in each index
i have done way, takes around 2 sec high dimensional matrices, looking more efficient way solve it.
for i=1:2 j=1:2 votes=[]; k=1:length(arrs) // arrs cell array of matrices votes=[votes arrs{1,k}(i,j)]; end res(i,j) = mode(votes); end end
create 3 dimensional array composed of x,y,z
, call mode
along third dimension desired result.
xyz = cat(3,x,y,z); ans = mode(xyz,3); ans = 7 2 8 10
Comments
Post a Comment