I have some 4D image data, 384-by-276-by-20-by-5, where data(X,Y,T,V)
, X = x location
, Y = y location
, T = time
, V = vessel location
.
I would like to have a mean value over time and maximum value over time for the data to get the pattern of my signal and thus set the value of my threshold value. I do it in loop so I could get say, for example data(1,1,:,1)
, a mean value for that开发者_运维知识库 point over time.
I tried mean(data(X,Y,:,V))
and mean(squeeze(data(X,Y,:,V)))
but it is giving me the error "Subscript indices must either be real positive integers or logicals."
I search everywhere but the example of mean value are only for 2D and 1D. I reckon, if I want to get a mean/max value of the data over time, the data is to be data(X,Y,:,V)
which is now 3D data.
Any help or idea about how to do this?
You can specify the dimension over which to take the mean by passing it as a second parameter to the MEAN function. Then you can remove singleton dimensions using the SQUEEZE function to get a 3-D matrix:
meanData = squeeze(mean(data,3));
The same procedure can be followed for finding the maximum using the MAX function, although you will have to add an empty parameter []
before you specify the dimension to operate over:
maxData = squeeze(max(data,[],3));
To analyze your problem, start from the error message: "Subscript indices must either be real positive integers or logicals." Do you understand what it means? If not, does it contain words you are not sure what they mean? Can you read up about them in the documentation? Can you google the whole error message?
The reason behind this is that you need to understand how MATLAB accesses elements of your 384-by-276-by-20-by-5 array; your problem has nothing to do with taking means or maxima, therefore searching for those terms didn't help.
When you type
data(X,Y,T,V)
then X,Y,T,V need to be integers (or vectors of integers), i.e. X must be in the range 1:384 and so on. For example,
mean(data(1,1,:,1))
will give you the temporal mean for the first X,Y and V points.
That said, you were saying you use a loop... have a look at what
mean(data,3)
and
max(data,[],3)
do... this should completely replace your loop if I understood your problem correctly.
mean(data,3)
and
max(data,[],3)
精彩评论