In CODE 1, the part while(true) {…} should be inside loop() eventually without a while(true).
In Code 3, you NEVER call matlab(), receive-data(), send-data().
https://www.arduino.cc/en/Reference/Loop/
And why are you using Serial.begin(57600), very slow, whereas you can use Serial.begin(250000) ?