Matlab Function in Simulink: Code Generation Error

조회 수: 9 (최근 30일)
Mark Trudgen
Mark Trudgen 2022년 6월 15일
댓글: Christopher Stapels 2022년 6월 17일
Hi there,
I am trying to implement the matlab function below (from a .m file) as a function block in simulink. The main gist is that it reads a string from thingspeak, then splits that string into data points.
I am getting errors stating that most of the functions from matlab (split, thingspeak...) are unavailable for code generation.
We cannot use the simulink thingspeak blocks as they only support numeric data, and we are processing large strings.
What can I do to make this work?
function [out0,out1,out2,out3,out4,out5,out6,out7,out8,out9,out10,out11,out12,out13,out14,out15,out16,out17,out18] = fcn()
data = thingSpeakRead(1747813, "Fields",1,"ReadKey","M005PRKFNU6BQ3R3", OutputFormat="timetable");
disp(data)
%defines delimiter
delimiter1 = "*";
delimiter2 = ",";
%converts timetable data into an array so it can be processed below
dataConvert = table2array(data);
%splits string into a 19x1 array
stringSplit = split(dataConvert, delimiter1);
%assigns location within array to variable
val0 = stringSplit(1);
val1 = stringSplit(2);
val2 = stringSplit(3);
val3 = stringSplit(4);
val4 = stringSplit(5);
val5 = stringSplit(6);
val6 = stringSplit(7);
val7 = stringSplit(8);
val8 = stringSplit(9);
val9 = stringSplit(10);
val10 = stringSplit(11);
val11 = stringSplit(12);
val12 = stringSplit(13);
val13 = stringSplit(14);
val14 = stringSplit(15);
val15 = stringSplit(16);
val16 = stringSplit(17);
val17 = stringSplit(18);
val18 = stringSplit(19);
%splits string a second time to a 1x2 array of shape [identifier,value]
splitStringVal0 = split(val0,delimiter2);
splitStringVal1 = split(val1,delimiter2);
splitStringVal2 = split(val2,delimiter2);
splitStringVal3 = split(val3,delimiter2);
splitStringVal4 = split(val4,delimiter2);
splitStringVal5 = split(val5,delimiter2);
splitStringVal6 = split(val6,delimiter2);
splitStringVal7 = split(val7,delimiter2);
splitStringVal8 = split(val8,delimiter2);
splitStringVal9 = split(val9,delimiter2);
splitStringVal10 = split(val10,delimiter2);
splitStringVal11 = split(val11,delimiter2);
splitStringVal12 = split(val12,delimiter2);
splitStringVal13 = split(val13,delimiter2);
splitStringVal14 = split(val14,delimiter2);
splitStringVal15 = split(val15,delimiter2);
splitStringVal16 = split(val16,delimiter2);
splitStringVal17 = split(val17,delimiter2);
splitStringVal18 = split(val18,delimiter2);
%assigns value to output variable to be used by simulink file
out0 = splitStringVal0(2);
out1 = splitStringVal1(2);
out2 = splitStringVal2(2);
out3 = splitStringVal3(2);
out4 = splitStringVal4(2);
out5 = splitStringVal5(2);
out6 = splitStringVal6(2);
out7 = splitStringVal7(2);
out8 = splitStringVal8(2);
out9 = splitStringVal9(2);
out10 = splitStringVal10(2);
out11 = splitStringVal11(2);
out12 = splitStringVal12(2);
out13 = splitStringVal13(2);
out14 = splitStringVal14(2);
out15 = splitStringVal15(2);
out16 = splitStringVal16(2);
out17 = splitStringVal17(2);
out18 = splitStringVal18(2);
end
  댓글 수: 3
Mark Trudgen
Mark Trudgen 2022년 6월 15일
Windows 11 for simulink
ESP32 for thingspeak data publishing.
Christopher Stapels
Christopher Stapels 2022년 6월 17일
Simulink is terrific, but they havent made all the functions code gernation capable yet. You can program the ESP32 directly with Arduini IDE in C, we have many examples in our doc to help with that. C has ok string manipulation, though not as easy as the MATLAB functions.

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

답변 (0개)

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by