How to obtain real time analog data and store it in an array?

12 views (last 30 days)
I have a potentiometer through which I need to take in inputs continuously and store in an array so that I plot it later. I take in inputs through Arduino Uno which I have successfully interfaced with MATLAB. I can obtain the voltage value at a given instant. But I need to store the value at each time into an array. Can anyone suggest any method to do that? Thanks
I use MATLAB 2014a version.
Please excuse if it is a simple/silly question. I am just a beginner.

Accepted Answer

Geoff Hayes
Geoff Hayes on 8 Dec 2014
Srinidhi - how many of these voltages to you expect to acquire? if you need to store the value in an array, then you can do so by just creating the array ahead of time (outside your for or while loop) and then update that array with the voltage data. Consider the following
% create an array of 10000 elements to store the voltage data
voltageData = zeros(10000,1);
% track the current voltage index
voltageIdx = 0;
% communicate with Arduino
while true
% get the voltage data
voltValue = ...;
% save it to the array
voltageIdx = voltageIdx + 1;
voltageData(voltageIdx) = voltValue;
end
Without knowing exactly how your code is written, you can try the above which will allow you to collect the voltage data over time.

More Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!