Hi mukti, I’m working on something pretty similar at the moment, give me an example of your serial string and I’ll see if I can help you out.
What I am doing is taking ADC data from an 8052 an processing it with MATLAB, I haven’t figured out how to parse my sting yet but I can import it into MATLAB with this code:
*******************************************************************
% Function: STRINGGET
%
% Description: Spectialy made code for capturing a paticular string
% String Description: <-...,w,w,w,w,w,w,1,2,B444,B444,.......,B444,w,w,w,w,w,...->
% Trigger: '$'
% Serial Port Terminator: 'w'
%
% Inputs: ADuC842 UART serial string
% Outputs: serial string
s = serial('COM1');
set(s,'BaudRate',2400, 'Parity','none', 'Terminator', 'w', 'InputBufferSize', 4500);
fopen(s);
fprintf(s, '$');
A = fgetl(s);
strlength = length(A);
while strlength < 2000
A = fgetl(s);
strlength = length(A);
end
A
fclose(s);
delete(s)
clear s
***************************************************************************************
My sting is constant like your one. When it is in idle mode it prints w,w,w,w,w,w,w,w,w,w
And when I send a trigger ‘$’ the micro controller goes w,w,V00B5,R004E,T0432,t00,#00,……
It goes on like that for about 4000 CHAR and then goes back to w,w,w,w,w,w,w,w.
SO.. I set my terminator to w and set my buffer size to 4500 and used fgetl(s) to get the string
Pay close attention to my command “set(s,’…….’)” this is the most important one for setting your serial port parameters.
Are you sure? This action cannot be undone.
That doesn't sound too bad, at least I think it can be done. Write a function that parses the string to an array and put your plotting commands at the end of the function.
I used a command like this recently:
while k(N) ~= 'W'
character = textscan(k(N), '%c', 1);
N = N + 1;
stChar = char(character);
iChar = sscanf(stChar, '%x');
‘W’ is the end of my string, so this bit of code looks at every individual character in the string when I’m parsing it. Textscan is a very versatile tool and can no doubt make your life easier.
I would tell you exactly how to parse your string but all I know about it is that it looks like startxxxxend
Linspace is a good tool for plotting, it allows you to generate a pot of something without knowing all of the details.
y = linspace(a,b)
Consult the MATLAB help for to see how to use these better.
To use linspace what I do is:
I take (my data) = x;
Which is an array -> [1 2 3 4 5 6 7 8 9 0];
And then I say z = count(x);
And then y = linspace(1, z);
This gives me two arrays of the same dimensions x and y
So I can just say plot(x, y);
One final thing you should think about!
Consider using SIMULINK, it’s a MATLAB thing, like a different sort of workspace, it might make things easier working in real time, might not, who knows.
Are you sure? This action cannot be undone.