()-indexing must appear last in an index expression

1 次查看(过去 30 天)
I have a 70x70x328 matrix and want to take the mean along either the first or second dimension (they're the same) while ignoring elements that are 0. I'm getting the error: ()-indexing must appear last in an index expression but don't know how to rearrange or what to add to my expression. Here's what I have
for i=1:length(files)
Mean1(:,i)=mean(All_files(:,:,i)(All_files(:,:,i)~=0),2);
end
Thanks!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2011-10-1
EDIT
Mean1 = squeeze(sum(data)./sum(data~=0))%first dimension
Mean2 = squeeze(sum(data,2)./sum(data~=0,2))%second dimension

更多回答(1 个)

Image Analyst
Image Analyst 2011-10-1
See if this works for you:
m = randi(9, [70,70,328])-1; % 70x70x328
sumAlongDim2 = squeeze(sum(m, 2)); % 70x328
binaryVolume = m ~= 0; % 70x70x328
countAlongDim2 = squeeze(sum(binaryVolume, 2)); % 70x328
% Compute the average.
meanAlongDim2 = sumAlongDim2 ./ countAlongDim2;
imagesc(meanAlongDim2);

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by