Summing over the same category within one column

Hi there,
I attached a rough sketch of my matrix to better describe the problem.
I have troubles summing over the same category within one column. I guess I would have to define that there are 14 categories first? I could also reshape every column in a loop? I am not sure how to proceed?
I am very grateful for help :)

6 commentaires

KSSV
KSSV le 8 Mai 2017
What is class of your matrix?
Lisette
Lisette le 8 Mai 2017
numeric double
Adam
Adam le 8 Mai 2017
Your screenshot isn't from Matlab so are you asking how to put your data in a matrix in the first place?
KSSV
KSSV le 8 Mai 2017
How cat1, cat2 etc strings present? What are those?
Lisette
Lisette le 8 Mai 2017
I already have the matrix in Matlab. I just wrote Category1, Cat2 etc. to illustrate the structure. In Matlab those are all numbers with a value betweeen 0 and 1.
Jan
Jan le 8 Mai 2017
The picture is not clear. What exactly does "Cat 1" mean? Where is which information stored and which data do you want to sum? Please use standard Matlab syntax to explain the input data.

Connectez-vous pour commenter.

 Réponse acceptée

Adam
Adam le 8 Mai 2017
Something similar to this should work, although your matrix sizes don't correspond with your comments. You say you have a 3500*3500 matrix. If this is divided into 14 then it gives you 250 categories.
This is just off the top of my head so there may be errors, but it should give the idea. There are probably ways without for loops to by rearranging the data order first, but get the answer right before looking for faster solutions!
inputIdx = 1:14:3487;
for n = 1:250
outputIdx = ( 1:14 ) + ( n - 1 ) * 14;
outputMatrix( outputIdx, : ) = sum( inputMatrix( inputIdx + n, : ) );
end

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by