Go Down

Topic: new column of data in Serial Monitor (Read 5651 times) previous topic - next topic

oximeter

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

Coding Badly


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.

robtillaart

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

Can you post your matlab code?
And Arduino code ?

Rob Tillaart

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

oximeter

#3
Jan 15, 2013, 12:46 am Last Edit: Jan 15, 2013, 12:59 am by oximeter Reason: 1
Hello,

this is one part of arduino code
Code: [Select]
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: [Select]
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: [Select]
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: [Select]
.
.
.
plot(data(:,1),data(:,3);
drawnow;
.
.
.



so, is it possible, and how?

thank you for your help!!!

Coding Badly


Try this...

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


oximeter

I tried, but it doesn't work...it doesn't read third column...  :(

oximeter

as I know, arduino writes results as "string", so I wrote this code in Matlab:
Code: [Select]
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...

PaulS

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

robtillaart

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

Code: [Select]
% 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 ?
Rob Tillaart

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

Go Up