I am trying to send a value to an arduino from Matlab and read serial data with fscanf() in matlab from the arduino.
My requirements are that i need to be able to send the data at a specified time interval i.e 20 values persecond at .05 seconds. and i need to be able to graph the incoming data and be able to save it for later use. I will know the length of the array before I start I have read and seen that this can be used to speed up the process.
The problem i am currently having is that each iteration of the loop becomes successively longer which throws the time behavior off more. I believe this to be due to the growing array inside of the loop I have.
x = linspace(0,time1,tosd)'; x1 = amp*sin(x*(2*pi/20)) + offset; y = zeros(length(x),1); i = 1; figure(1); hold on; title('Pressure Data'); xlabel('Data Number'); ylabel('Analog Voltage (0-1023)'); t1 = zeros(length(x),1); figure(2); hold on; title('Time to execute task'); xlabel('iteration number'); ylabel('time taken'); while (i<=length(x)) t2 = tic; t = tic; fprintf(handles.UltraM,(['<P' num2str(x1(i)) '>'])); disp((['<P' num2str(x1(i)) '>'])); y(i) = fscanf(handles.UltraM,'%i'); figure(1); hold on; plot(i, y(i), 'b*'); plot(i, pressure, 'b*'); drawnow; hold off; while toc(t) < 0.05 continue end t1 = toc(t2); figure(2); hold on; plot(i,t1,'b*'); drawnow; hold off; i = i + 1; end
The last tic toc finction is just used so that i can graphically see the slowdown time.
thank you in advance for any help