Effacer les filtres
Effacer les filtres

()-indexing must appear last in an index expression

3 vues (au cours des 30 derniers jours)
Emily
Emily le 1 Oct 2011
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!

Réponse acceptée

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

Plus de réponses (1)

Image Analyst
Image Analyst le 1 Oct 2011
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);

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by