How to run an if statement in a cell?

I have a cell containting 125 by 125 elements where each element contains a local 36 by 36 array of data. I am new to this sort of work and I am currently carrying out some data analysis. I want to be able to determine if any of the local data (so data within the 36 by 36 array) are greater than 10% of the local average, but this needs to be done for the whole cell. I can carry this procedure out separately but this is not efficient. Am I correct that an 'if' statement would be able to get the job done? Any help on this would be greatly appreciated.

2 Comments

Probably cellfun will help you.
What do you want exactly as output? A logical 36x36 array for each cell determining which element is greater than the 10% of the mean of the 36x36 elements?
Yes that would be the output I would want.

Sign in to comment.

 Accepted Answer

A possible soution:
sol = cellfun(@(in) in > 0.1*mean(in(:)),A,'uni',0); %where A is your cell array

7 Comments

That is perfect, thank you very much!
Is there a way to then output the final cell as a 125 by 125 logical where if any of the data in the 36 by 36 elements is over 10% of the mean? Or is this not possible?
Many thanks for your help so far.
It can be done, but It will be allways true (at least 1 element must be greater than the 10% of their local mean).
sol = cellfun(@(in) any(any(in > 0.1*mean(in(:)))),A);
Hi Alex, is it possible to put two limits within the cellfun? As in 10% either side of the mean?
Yes, just putting an '&' operator between conditions:
sol = cellfun(@(in) any(any(in > 0.9*mean(in(:)) & in < 1.1*mean(in(:)))),A);
Thank you.
Finally, and I understand this may not be possible. But what I am essentially doing is treating the original data set as pixels. So every point of data is a pixel that has detected a photon on a detector screen. I initially had a 4500 by 4500 array which I managed to split into a 125 by 125 cell with each element containg 36 by 36 pixels thanks to your help. I am looking at finding the number of defected pixels on the whole device (a defected pixel is one with a signal level >10% away from the mean either side, so < 0.9*mean and >1.1*mean are defined as defected pixels). Using your help I have managed to find the number of defected elements, and in them I have found the locations of the defected pixels and added them up, but that section is hard coded and can be tedious.
I wondered if there was a way to count all the defected pixels using code instead of counting all the defected areas myself. For example, here is the code I used to find the defected pixels for one of the data sets:
L900 = cellfun(@(in) in > 0.9*mean(in(:)) & in < 1.1*mean(in(:)),PRNU900_Cell,'uni',0);
DeflectedPixelsTest = sum(length(find(L900{123,2}>0))+length(find(L900{78,13}>0))+length(find(L900{31,17}>0))+length(find(L900{4,24}>0))+length(find(L900{93,24}>0))+length(find(L900{22,25}>0))+length(find(L900{23,25}>0))+length(find(L900{11,39}>0))+length(find(L900{92,41}>0))+length(find(L900{120,43}>0))+length(find(L900{62,53}>0))+length(find(L900{76,65}>0))+length(find(L900{103,69}>0))+length(find(L900{11,79}>0))+length(find(L900{32,84}>0))+length(find(L900{106,114}>0))+length(find(L900{107,114}>0))+length(find(L900{55,117}>0))+length(find(L900{81,119}>0)));
So as you can see, there were 19 defected regions in the whole of my L900 cell and I located them and counted the number of defected pixels within each of them.
Do you know of a more simpler way to do this? Sorry if this was confusing, let me know if anything needs clearing up. Thanks!
"Do you know of a more simpler way to do this?"
Take a look at blockproc, histcount, histcounts2, etc..

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!