MATLAB does not need to know which Arduino sketch file you are using. Here is the procedure of what you need to do.
- You will first program your Arduino board, with the given code, using Arduino IDE. Download the Arduino code, open the Arduino IDE and create a new file and paste the downloaded code in the new file. Upload the program to the Arduino board.
- Note the port number for Arduino board from the Arduino IDE. Go to Tools menu > Port and note the port number such as COMx.
- After uploading the code, keep the Arduino connected using USB cable and open MATLAB.
- In the MATLAB code change the line
and change COM6 to COMx you noted from MATLAB.
Now when you run the MATLAB code, it will communicate with the Arduino.