Obatin the sum from reading columns from 2 matrices
Mostrar comentarios más antiguos
Hi,
I have matrix A=(5479 x 378) and RowID matrix (15 x 2). I need to get the sum for each column of A for RowIDs 1:15
for id=1:378
for ix=1:1:15
St(ix,1)=sum(new(:,id)([RowID(ix,1):RowID(ix,2)],:));
end
end
Error: ()-indexing must appear last in an index expression.
This is the error I am getting when I run the above code. Can somebody help me to fix that please?
Thanks in advance.
3 comentarios
the cyclist
el 17 de Jun. de 2014
I have no idea what you are trying to do. Do you think you could create a much smaller, self-contained example that is representative of what you are trying to do, with sample input and expected output ?
Maybe you could have A be (5 x 4) and RowID be (3 x 2), just as a "toy" example?
the cyclist
el 17 de Jun. de 2014
Sorry for continuing to ask questions, but I am trying not to waste your time with an inaccurate solution.
Could you ever have something like
RowID = [1 5; 6 8]
where you are summing more than two consecutive rows?
Respuestas (1)
the cyclist
el 17 de Jun. de 2014
Does this do what you want?
numberSets = size(RowID,1);
St = zeros(numberSets,size(new,2));
for ns = 1:numberSets
St(ns,:) = sum(new(RowID(ns,1):RowID(ns,2),:),1);
end
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!