()-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!
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!