Olivier_s_j
Olivier_s_j

Reputation: 5202

Sum over the rows of a cell matrix

I have a variable classi which is composed out of cells (269x500), it can be found here http://ojtwist.be/data.mat . I'm trying to sum the rows of this matrix so that i get a vector of 269x1. I tried converting the variable to a matrix with cell2mat but this doesn't work. Or matlab sees the sign (-) as a seperate cell. Therefore i can't use sum(classi(:),2). My question is now, how can I do this efficiently ?

Thx

Upvotes: 3

Views: 438

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38042

Here's how you could do it:

load data.mat

a = sum( cellfun(@str2double, classi), 2);

Upvotes: 2

Related Questions