6 views (last 30 days)

Hi,

I have a 51x51 2D matrix that I need to take a mean off, but it has to give me back a 51x51 2D matrix as an output.

Please see the sample code below:

rand_image_stim = rand(10000,51,51);

kk = 1:length(rand_image_stim);

firing_rate_kk(kk) = 0;

gab_filt = z_cos.*z_gauss;

lp(kk) = 0;

for kk = 1:length(rand_image_stim)

output_kk = squeeze(rand_image_stim(kk,:,:)).*gab_filt;

firing_rate_kk(kk) = sum(output_kk,'all');

jk = squeeze(rand_image_stim(kk,:,:))*firing_rate_kk(kk);

lp = mean(jk,2); %this is where I need help

end

Luna
on 13 Nov 2019

Edited: Luna
on 13 Nov 2019

your for loop is length(rand_image_stim). So your mean value calculated 10000 times. You should store it and later get the mean all.

Try this:

rand_image_stim = rand(10000,51,51);

kk = 1:length(rand_image_stim);

firing_rate_kk(kk) = 0;

gab_filt = z_cos.*z_gauss;

lp(kk,51) = 0; % 10000 x 51 matrix

for kk = 1:length(rand_image_stim)

output_kk = squeeze(rand_image_stim(kk,:,:)).*gab_filt;

firing_rate_kk(kk) = sum(output_kk,'all');

jk = squeeze(rand_image_stim(kk,:,:))*firing_rate_kk(kk);

lp(kk,:) = mean(jk,2); %this is where I need help

end

your_mean_value = mean(lp,'all');

Luna
on 13 Nov 2019

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766828

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766828

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766834

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766834

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766835

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766835

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766846

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766846

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766856

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766856

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766861

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766861

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766867

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766867

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766903

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/490863-mean-of-a-matrix#comment_766903

Sign in to comment.