Pages: [1]   Go Down
Author Topic: new column of data in Serial Monitor  (Read 3866 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,

in arduino serial monitor, I acquire three columns of different data seperated with tab "Serial.print("\t");  "
If I read that data in Matlab, it doesn't recognise those data as three columns, but one.

is there any "Serial.print("???")" that helps to write each data in next column, that Matlab will be able to recognise it as next column?

thanks
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


You will have to provide more detail.  For example, are you using regexp?

I frequently use tab as separator.  In general it's a good choice for text data.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IIRC matlab uses a ; or a , as default separator. Try one of those

Can you post your matlab code?
And Arduino code ?

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

this is one part of arduino code
Code:
Serial.print("\t");
  Serial.print(freq(), DEC);
  Serial.print("\t");
  Serial.print("");   
  Serial.print(osvet(), DEC);
  Serial.println("\t");

it gives me this results on Serial Monitor (where the left column is counter), and the other two columns are other data
Code:
1 800 86956
2 800 86956
3 790 85869
4 790 85869
5 780 84782
6 780 84782
7 780 84782
8 780 84782
9 780 84782
10 790 85869


Ok, now I want to read this in Matlab
Code:
s = serial('COM4', 'BaudRate', 9600);
fopen(s);

for i= 1:2000

data=fscanf(s);
y(i)=str2double(data);
plot(i,y(i));
drawnow;
hold on
end
fclose(s);

but I want to plot third column (y), and first coulmn (x)...
actually I want to do that:
Code:
.
.
.
plot(data(:,1),data(:,3);
drawnow;
.
.
.


so, is it possible, and how?

thank you for your help!!!
« Last Edit: January 14, 2013, 06:59:42 pm by oximeter » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Try this...

Code:
  data=fscanf( s, '%d %d %d', 3 );

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried, but it doesn't work...it doesn't read third column...  smiley-sad
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

as I know, arduino writes results as "string", so I wrote this code in Matlab:
Code:
data=fscanf( s, '%s',3 )
y(i)=str2double(data)
plot(i,y(i));

drawnow;
hold on
ok, it gives me something, but it is not correct... :/

and another question: How can I connect dots in "real time" graph in Matlab? I have discrete measurments, and it plot me only seperated points...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you using single quotes around strings? In C, at least, single quotes are for characters, and double quotes are for strings.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if i look at this  - http://www.mathworks.nl/help/matlab/ref/fscanf.html -

Code:
% Create a file with an exponential table
x = 0:.1:1;
y = [x; exp(x)];

fid = fopen('exp.txt', 'w');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid);

% Read the data, filling A in column order
% First line of the file:
%    0.00    1.00000000

fid = fopen('exp.txt');
A = fscanf(fid, '%g %g', [2 inf]);
fclose(fid);

% Transpose so that A matches
% the orientation of the file
A = A';

looks like you miss the fid ?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: