Matlab Function in Simulink: Code Generation Error

6 Ansichten (letzte 30 Tage)
Mark Trudgen
Mark Trudgen am 15 Jun. 2022
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 Kommentare
Mark Trudgen
Mark Trudgen am 15 Jun. 2022
Windows 11 for simulink
ESP32 for thingspeak data publishing.
Christopher Stapels
Christopher Stapels am 17 Jun. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu Visualize Data finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by