필터 지우기
필터 지우기

Convert a date into seconds from a string from a block "constant"

조회 수: 1 (최근 30일)
Nadege Hervieux
Nadege Hervieux 2017년 9월 29일
댓글: Nadege Hervieux 2017년 10월 3일
I am trying to convert a date in the form 'DD.MM' - set in a constant block - into seconds in Simulink (so that the user can change it quickly). I found the following guidelines to solve the issue by it still does not get through. 1. In the block I entered uint8(DD/MM) 2. Here is the code in the function: function seconds = fcn(date) coder.extrinsic('sscanf'); coder.extrinsic('datenum'); seconds=0; sscanf(date,'%d.%d'); seconds= datenum(date,24); end
I got the following error: "First argument must be a string."
Any hint?.

채택된 답변

Nick Choi
Nick Choi 2017년 10월 2일
The error that is being generated is due to the following line of code:
sscanf(date,'%d.%d');
The 'date' variable comes out of the constant block as a 'double' variable so it needs to be type casted to a 'string' in order to be used by 'sscanf'.
In Simulink, the constant block cannot output 'string' variables as described in the following documentation page: https://www.mathworks.com/help/simulink/slref/constant.html#bslolcd-1
One thing to note is that 'DD/MM' in a constant block will return the result of the division.
  댓글 수: 1
Nadege Hervieux
Nadege Hervieux 2017년 10월 3일
Thanks Nick. Is there an appropriate block that could do the task I am trying to do, i.e. converting the date from a block into a function?
Thank you.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by