Borrar filtros
Borrar filtros

()-indexing must appear last in an index expression

3 visualizaciones (últimos 30 días)
Emily
Emily el 1 de Oct. de 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!

Respuesta aceptada

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

Más respuestas (1)

Image Analyst
Image Analyst el 1 de Oct. de 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);

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by