How to change sting type in stateflow to C char type?

조회 수: 2 (최근 30일)
jack
jack 2025년 2월 19일
댓글: jack 2025년 2월 21일
Now I have define a function in C file, For example ,Test_b(const char *a, uint8 b);Then I use stateflow shat to call the function tate_b(&c,d),c is defined in stateflow data whose type is string, d is also defined in stateflow data chose type is uint8; When I run simulink, it return a problem datatype is incompatible.
So I want to ask a question ,How to change sting type in stateflow to C char type?
  댓글 수: 1
jack
jack 2025년 2월 19일
I have Try to Use MATLABfunction,to convert string to char by using cnvertStringToChar, but it also return the problem "Attempt to conert the unsupported data type"

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

채택된 답변

Adarsh
Adarsh 2025년 2월 21일
Hi @jack,
I understand that you are trying to use a function defined in “C” file in Stateflow and getting error in conversion of data from string to char using “convertStringToChar” MATLAB function. An alternate method to give a char input to a “C” function is to convert the string input to ascii values using “str2ascii” function and passing the output to the “C” function leveraging the implicit conversion properties of the “C” function to automatically convert ascii values to their respective charversions as the input to the function is defined as char*.
For more information on how to utilize this method for type conversion and examples related to it, the following documentation link can be referred:
  1. “Custom code with string data” - https://www.mathworks.com/help/stateflow/ug/tutorial-custom-code-with-string-data.html
Hope it resolves the error.
  댓글 수: 1
jack
jack 2025년 2월 21일
Yes, I solved the problem through that method。 Thank you Very much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by