필터 지우기
필터 지우기

error code on cumsum

조회 수: 1 (최근 30일)
Ralph
Ralph 2014년 2월 23일
댓글: Ralph 2014년 2월 23일
I am attempting to run: A = 1 - cumsum(C)/sum(C); where C is a long column vector. I receive error "??? Error using ==> cumsum CUMSUM is not supported for integer input." What does it mean?
  댓글 수: 2
per isakson
per isakson 2014년 2월 23일
편집: per isakson 2014년 2월 23일
The code looks ok. Make this check
which cumsum -all
what does it say? And what does
class( C )
say? And which Matlab release do you use?
Ralph
Ralph 2014년 2월 23일
response to 'which cumsum -all' EDU>> which cumsum -all built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@single\cumsum) % single method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@double\cumsum) % double method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@logical\cumsum) % logical method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@uint8\cumsum) % uint8 method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@int8\cumsum) % int8 method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@uint16\cumsum) % uint16 method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@int16\cumsum) % int16 method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@uint32\cumsum) % uint32 method
built-in (C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\datafun\@int32\cumsum) % int32 method
Response to class (C) EDU>> class(C) ans = uint8
I have Matlab R2010a

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

채택된 답변

Image Analyst
Image Analyst 2014년 2월 23일
편집: Image Analyst 2014년 2월 23일
Try this. It works for me:
C = int32(randi(9, 1, 10)) % Array of integers.
A = 1 - cumsum(C) / sum(C)
  댓글 수: 3
Image Analyst
Image Analyst 2014년 2월 23일
Yes, MATLAB has an unintuitive of promoting/casting variable types. If C is double, it's fine. Regardless I can't find a way to duplicate the error the Ralph posted. Perhaps he can give some code that illustrates the error.
Ralph
Ralph 2014년 2월 23일
The suggestion above to use int32() provided an idea on how to proceed. i did not know how to identify what format my data was in, so the class() command helped with this. My data was uint8. Do I used double() to change the format of my data, and I got passed the cumsum error. Thanks for the assistance.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by