M = [
1 2 3 4
5 6 7 8
9 10 11 12];
E = [
4 2 1 2
2 3 4 1
1 3 2 3];
foo = @(m,e) m+randi(9,1,e)/10;
fun = @(m,e) [foo(m,e),m,foo(m,e)];
C = arrayfun(fun,M,E,'Uni',0);
Giving the output in a cell array C, where each cell contains a vector based on one element of M, e.g. the first column of C:
>> C{:,1}
ans =
1.4000 1.3000 1.9000 1.3000 1.0000 1.9000 1.1000 1.3000 1.9000
ans =
5.6000 5.6000 5.0000 5.9000 5.5000
ans =
9.1000 9.0000 9.3000
>>
" how do i store this data since it no longer stays as a matrix..."
I showed you how to put this into a cell array which is the same size as your original matrices. Alternatively you could extract all of the numeric data and concatenate it into one long numeric vector.
"...and is it possible use indexing to find a certain value eg. find(M==2)"
That depends on how your decide to store it: storing in a cell array requires a different way of searching than if you use one numeric vector.
Best Answer