[Num,Txt,R​aw]=xlsrea​d......

조회 수: 9 (최근 30일)
Cristina
Cristina 2012년 6월 15일
편집: Image Analyst 2022년 3월 20일
I used [Num,Txt,Raw]=xlsread to import a matrix containing both numerical and text data and Raw is a 2000*8 cell. When I try to compute eg mean(Raw(.,7)) the following message appears:
??? Undefined function or method 'sum' for input arguments of type 'cell'.
Error in ==> mean at 29 y = sum(x)/size(x,dim);
How can I convert cel into num values?
Thanks
  댓글 수: 2
C.J. Harris
C.J. Harris 2012년 6월 15일
Why don't you use the numeric data to compute the mean etc?
Cristina
Cristina 2012년 6월 15일
Because I have to make computations conditional to a list of variables.... e.g. Raw contains a colums country, rating... and I have to compute let's say the mean only if country=IT and rating=BBB. So I need both numerical and text data...

댓글을 달려면 로그인하십시오.

답변 (4개)

Kye Taylor
Kye Taylor 2012년 6월 15일
To convert cell to matrix use the cell2mat functions. For example,
mean(cell2mat(Raw(:,7)))

Andrei Bobrov
Andrei Bobrov 2012년 6월 15일
sum for arguments of type double
eg
mean(Num(:,7));
  댓글 수: 1
Cristina
Cristina 2012년 6월 15일
ok but this is not a conditional mean...I need to compute the mean if eg country='IT'

댓글을 달려면 로그인하십시오.


Peter Perkins
Peter Perkins 2012년 6월 15일
Cristina, if you have access to the Statistics Toolbox, you might find that using a dataset array is helpful the kind of thing you seem to be describing. You can read a spreadsheet into a dataset array, and then, for example, compute the mean of one variable conditional on values of other numeric or non-numeric variables.
This example on the File Exchange
seems more or less the kind of thing you are describing.

Syed Zubair shah
Syed Zubair shah 2022년 3월 20일
what does it means of Num , txt , Raw ... can we just assign it by T =xlsread(filename) ... if yes then how we call specific column then like F is a column of 1600 rows ?
[Num,Txt,Raw] = xlsread(filename)
  댓글 수: 1
Image Analyst
Image Analyst 2022년 3월 20일
편집: Image Analyst 2022년 3월 20일
[Num,Txt,Raw] = xlsread(filename, sheetName, 'F1:F1600');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by