I'm trying to send data from matlab to arduino via serail port using this code in Matlab:

 Arduino= serial ('COM4','BaudRate',9600);
while 1

and this in Arduino IDE:

int incoming;
void setup() {
void loop() {
  if (Serial.available()) {
    incoming = Serial.read();
    Serial.print("I received: ");
    Serial.println(incoming, DEC);

I've connected my Arduino Uno. "seriallist" command on matlab says:

ans = 

I'm getting this error in matlab:

Error using serial/fopen (line 72) Open failed: Port: COM4 is not available. No ports are available. Use INSTRFIND to determine if other instrument objects are connected to the requested device.

What's wrong with the serial port? Why matlab can't open it?

  • We always want to get rid of the error, don't we? I added my question. – 2012User Apr 28 '19 at 22:26
  • Can you open it in the IDE? Do you have it open in the IDE at the same time you're trying to use it in Matlab? – Majenko Apr 28 '19 at 22:29
  • Yes, Arduino IDE is open too. – 2012User Apr 28 '19 at 22:44
  • It's about if you have the IDEs serial monitor open at the same time when you try to connect matlab. Only 1 program can use the serial port at a time – chrisl Apr 28 '19 at 23:01
  • No ofcourse not. Serial monitor is not open. – 2012User Apr 28 '19 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.