Thanks for your help, I actually fix the issue thankfully by limiting the number of times Arduino performs Serial.println(). You were right on the inefficiency of my previous code but I had the same problem on a faster code. It is at the expense of some latency but I was able to solve the issue where MATLAB sends a request to the Arduino where it then returns a string.
The new code is based from this model I created to sample at intervals.
if true
SF = 10; % Samples per second
n = 1;
Time = 0;
Clock = tic;
while n < 10
if toc(Clock) >= Time + 1/SF
Time = toc(Clock)
n = n + 1;
end
end
end
Before I had it to where Arduino was sending continuous data, but I suspect the MATLAB engine has a bug with the fscanf() under the conditions deployed with GUIDE. Arduino may be to fast for MATLAB in the manner I previously used.
if true
while n < 10000
if (handles.timer + toc) >= timer + 1/10
timer = timer + round(toc*10)/10;
% Begin data acquisition.
fprintf(s, 'A'); % here is where the request was sent.
input = fscanf(s, '%f %f'); % here is where MATLAB receives data.
Time(n) = timer;
RPM(n) = input(1,1);
% End data acquisition.
n = n + 1;
end
pause(0.000001) % needed to break loop via button.
tic
end
end