Using fscanf, won't print out second row of data
古いコメントを表示
I'm having trouble using the fscanf command to show the two different data points that are being sent over a com port. The data that is coming from the com port looks like this:
X,Y
1,6
2,5
3,4
4,3
5,2
6,1
Where each set of 0,0 is in a single cell.
I would like the data to look like this
X: 1, 2, 3, 4, 5, 6
Y: 6, 5, 4, 3, 2, 1
Please help if you can! I need to get this working soon. Thank you in advance!
%% Clearing COM PORTS
delete(instrfindall)
%% Create the serial object
serialPort = 'COM4';
serialObject = serial(serialPort,'BaudRate',38400, 'DataBits',8);
fopen(serialObject);
%% Set the instrument in remote mode
fprintf(serialObject,'%f,%f');
%% Set the time span and interval for data collection
stopTime = '14:31';
timeInterval = 0.0025;
%% Collect data
count = [1,1];
while ~isequal(datestr(now,'MM:SS'),stopTime)
time(count) = datenum(clock);
position(count) = fscanf(serialObject,'%f,%f');
pause(timeInterval);
count = count +1;
end
fclose(serialObject);
delete(serialObject);
clear serialObject;
採用された回答
その他の回答 (2 件)
Brandon
2013 年 2 月 11 日
0 投票
3 件のコメント
Walter Roberson
2013 年 2 月 11 日
Remember, position(count) is not going to store two values.
Brandon
2013 年 2 月 11 日
Walter Roberson
2013 年 2 月 11 日
position(count,:) = fscanf(serialObject,'%d,%d');
カテゴリ
ヘルプ センター および File Exchange で Use COM Objects in MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!