Serial communication with matlab

hi!
I've been trying to send the values generated in the arduino to matlab for plotting. I got this code in the following linkhttp://allaboutee.com/2011/07/04/how-to-send-data-from-the-arduino-to-matlab/

This is the code for the arduino

int i=0;
void setup() 
{
  Serial.begin(9600);
}
 
void loop() 
{
   Serial.println(i);
   i++; 
}

and this is the code for matlab

clear all
clc
 
arduino=serial('COM4','BaudRate',9600);
 
fopen(arduino);
 
x=linspace(1,100);
   
for i=1:length(x)
	y(i)=fscanf(arduino,'%d');
end
	
fclose(arduino);
disp('making plot..')
plot(x,y);

I'm facing an error when I try to run the code for matlab. I've attached the error message. I know this might not be very appropriate place to ask question on matlab. But I believe there will be someone who can help me out who has dealt with arduino and matlab serial communication.

Why did you waste bandwidth and force us to download a picture of text? Haven't you a clue how to copy text?

Why do you assume that the Arduino is on COM4? Matlab is telling you that it isn't.

Arduino is connected to the Com4...I don't know why Matlab is not recognizing it. I verified it in the device manager.

Apologies for wasting the bandwidth

Well the error shows COM4 is not available. Do you have the arduino serial console also opened at the same time?