Code Generation Readiness - strsplit() and datenum() are unsupported function calls?

조회 수: 11 (최근 30일)
Hello to all, I am curious about Code Generation Readiness. I tried to check a file with these lines:
function teststrplit()
fileName = 'xxx_yyyyyyy_20141205.mat';
strsplit(fileName,'_');
datenum(fileName(13:end-4),'yyyyMMdd');
And it is evaluated with readiness score of 3 because of "Unsupported MATLAB function calls". Why these functions are evaluated as less readable? I got invocation for both, strsplit and datenum. I am working in Linux, MATLAB R2015b. Thanks for explanation or comments.

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 18일
strsplit involves cell arrays. There are a number of restrictions on cell arrays for code generation; see http://www.mathworks.com/help/simulink/ug/cell-array-restrictions-for-code-generation.html
You can grab a source for strsplit from the File Exchange and modify it to fit the requirements.
Have you considered using indexing?
filedate = fileName(find(fileName == '_', 1, 'last'):end-4);
I am not sure why datenum() is not supported for code generation. Since you have a fixed date format, you could write some small code to do the conversion. Look up the month number in a cumulative-days-before list, add the day number, pre-calculate the serial date for the beginning of the first year you want to consider, add that to 365 times the difference between the file year and the current year, make leap-year corrections.
  댓글 수: 2
Petr Dvorak
Petr Dvorak 2015년 9월 23일
Dear Walter, thanks for the comment and the link. It doesn't cause a big problem, I was curious. Now I can understand the cell-problem but the strsplit is strange. Anyway, I can live without it. Thank you again.
Walter Roberson
Walter Roberson 2015년 9월 23일
strsplit is defined as returning a variable-length cell array, since you do not know ahead of time how many pieces the string will split into.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by