I have two serial port data output I and Q, how do I make a column table with I and Q? My output is like this.

6 visualizaciones (últimos 30 días)
{"I":[2013,2053,2073,2049,2027,2025,2073,2039,2073,2053,2073,2039,2063,2053,2077,2049,2043,2005,2051,2033,2057,2049,2033,2039,2069,2065,2025,2053,2065,2033,2067,2019,2015,2039,2055,2081,2025,2035,2051,2039,2053,2053,2037,2041,2055,2037,2069,2069,2083,2053,2029,2029,2027,2077,2081,2073,2025,2051,2071,2031,2077,2057,2089,2037,2059,2041,2053,2015,2021,2057,2035,2023,2049,2027,2039,2075,2051,2041,2071,2035,2077,2033,2077,2049,2051,2027,2033,2033,2051,2065,2049,2075,2089,2023,2059,2041,2051,2041,2059,2027,2063,2041,2035,2051,2071,2093,2025,2043,2077,2017,2051,2027,2029,2055,2053,2057,2067,2051,2021,2063,2041,2029,2055,2035,2031,2061,2017,2041,2031,2029,2039,2061,2093,2023,2011,2063,2027,2029,2043,2019,2055,2055,2033,2027,2077,2033,2041,2075,2059,2083,2037,2059,2051,2053,2035,2017,2031,2033,2015,2053,2049,2025,2059,2053,2035,2069,2053,2023,2071,2025,2061,2039,2037,2023,2063,2053,2041,2029,2025,2053,2039,2049,2057,2071,2055,2083,2057,2067,2021,2071,2065,2067,2037,2055,2027,2065,2083,2069,2061,2039,2053,2029,2033,2063,2033,2027,2035,2085,2073,2035,2061,2035,2021,2065,2053,2041,2073,2049,2057,2041,2057,2041,2039,2073,2059,2051,2057,2043,2025,2059,2033,2031,2025,2065,2055,2021,2077,2041,2051,2049,2067,2069,2021,2017,2057,2061,2049,2057,2049,2075,2049,2055,2083,2039,2041,2035,2049,2029,2029,2065,2055,2067,2065,2035,2039,2079,2053,2031,2069,2035,2035,2063,2069,2065,2069,2061,2051,2069,2039,2035,2093,2041,2043,2071,2005,2017,2035,2057,2027,2033,2065,2023,2019,2057,2049,2029,2037,2017,2043,2059,2087,2061,2037,2055,2035,2033,2039,2041,2057,2075,2015,2009,2021,2075,2053,2079,2069,2091,2067,2053,2055,2051,2069,2063,2033,2073,2055,2033,2041,2041,2041,2051,2069,2035,2033,2071,2041,2027,2059,2061,2043,2051,2059,2025,2037,2053,2039,2037,2051,2053,2057,2071,2031,2055,2041,2031,2041,2065,2031,2055,2039,2059,2067,2025,2063,2023,2055,2057,2037,2035,2061,2013,2053,2055,2069,2039,2031,2029,2043,2025,2037,2057,2025,2041,2075,2043,2067,2071,2039,2057,2065,2063,2061,2037,2085,2097,2051,2067,2061,2023,2057,2049,2095,2039,2031,2065,2075,2039,2039,2061,2027,2037,2055,2053,2033,2057,2065,2059,2039,2077,2037,2071,2029,2035,2057,2055,2023,2039,2067,2089,2051,2049,2049,2019,2027,2067,2019,2039,2015,2055,2031,2033,2029,2017,2031,2055,2069,2021,2043,2065,2083,2035,2009,2039,2015,2049,2075,2081,2063,2065,2029,2035,2055,2025,2041,2057,2037,2055,2029,2033,2025,2033,2019,2083,2063,2037,2061,2021,2035,2053,2037,2041,2043,2057,2055,2071,2037,2031,2075,2041,2015,2025,2063,2017,2033,2009,2021,2049,2029,2033,2031,2083,2065,2085,2035,2051,2023,2051,2069,2019,2027,2075]}
{"Q":[2043,2037,2043,2043,2057,2041,2037,2043,2049,2043,2041,2041,2043,2053,2025,2039,2041,2057,2049,2035,2041,2041,2063,2053,2039,2037,2053,2037,2041,2033,2043,2049,2069,2043,2035,2035,2059,2043,2051,2043,2051,2055,2049,2037,2045,2041,2043,2055,2031,2041,2045,2041,2061,2035,2053,2031,2069,2041,2037,2053,2035,2053,2039,2049,2059,2043,2059,2053,2053,2039,2061,2049,2059,2053,2057,2051,2061,2033,2051,2043,2037,2057,2037,2039,2057,2057,2057,2061,2043,2035,2051,2043,2035,2039,2043,2043,2055,2041,2023,2039,2051,2029,2049,2053,2039,2039,2049,2041,2059,2041,2039,2055,2061,2035,2051,2043,2063,2041,2053,2035,2057,2053,2033,2051,2061,2053,2061,2051,2057,2041,2041,2061,2037,2041,2069,2037,2053,2027,2031,2057,2043,2031,2039,2043,2043,2053,2041,2049,2041,2049,2043,2027,2039,2051,2059,2059,2053,2037,2073,2039,2057,2041,2039,2049,2051,2041,2039,2053,2035,2051,2045,2053,2057,2037,2053,2031,2055,2055,2057,2033,2045,2051,2057,2051,2039,2023,2049,2035,2061,2051,2029,2035,2061,2049,2043,2033,2053,2029,2049,2055,2043,2053,2055,2039,2063,2041,2051,2035,2043,2029,2049,2041,2071,2055,2049,2059,2041,2037,2045,2031,2053,2049,2057,2039,2035,2051,2041,2037,2053,2049,2065,2049,2057,2051,2055,2039,2035,2039,2053,2037,2035,2043,2073,2037,2035,2051,2051,2049,2059,2029,2035,2037,2041,2051,2043,2043,2055,2053,2057,2037,2035,2041,2043,2053,2059,2053,2055,2039,2045,2041,2055,2037,2049,2031,2021,2039,2043,2035,2049,2055,2021,2049,2039,2019,2059,2055,2065,2025,2051,2053,2037,2043,2053,2049,2039,2061,2039,2061,2049,2029,2043,2035,2065,2039,2059,2053,2065,2039,2043,2033,2037,2059,2067,2037,2053,2035,2035,2037,2035,2053,2051,2037,2039,2049,2043,2035,2041,2055,2049,2043,2045,2043,2037,2037,2053,2035,2049,2051,2043,2051,2049,2037,2059,2035,2039,2037,2065,2049,2041,2023,2033,2043,2053,2021,2049,2051,2049,2049,2035,2039,2041,2037,2049,2049,2041,2057,2049,2035,2049,2035,2043,2049,2053,2037,2025,2043,2053,2055,2057,2059,2067,2055,2059,2051,2043,2057,2037,2033,2041,2049,2055,2033,2035,2059,2027,2025,2031,2033,2053,2037,2039,2043,2025,2043,2055,2041,2049,2041,2035,2049,2067,2037,2057,2037,2057,2041,2041,2049,2049,2041,2053,2037,2053,2037,2059,2041,2071,2051,2037,2031,2063,2039,2033,2041,2063,2055,2069,2031,2059,2039,2067,2053,2061,2053,2061,2049,2051,2057,2039,2049,2057,2035,2049,2051,2061,2043,2035,2041,2055,2035,2057,2021,2041,2043,2059,2039,2057,2059,2065,2055,2053,2053,2039,2043,2041,2037,2041,2051,2059,2051,2061,2035,2053,2049,2049,2051,2033,2053,2041,2051,2057,2057,2049,2057,2053,2039,2059,2043,2049,2051,2029,2037,2055,2037,2057,2033,2043,2043,2039,2065,2051,2019]}
{"I":[2041,2039,2041,2019,2027,2059,2065,2031,2053,2065,2073,2055,2025,2033,2067,2059,2021,2041,2055,2023,2035,2017,2043,2061,2003,2089,2035,2033,2067,2069,2063,2055,2049,2049,2049,2059,2073,2049,2057,2049,2017,2081,2027,2059,2059,2039,2043,2027,2065,2033,2017,2065,2057,2037,2037,2043,2049,2029,2033,2059,2101,2017,2025,2051,2051,2059,2053,2063,2077,2035,2055,2067,2033,2033,2059,2055,2051,2067,2085,2055,2037,2057,2085,2069,2029,2087,2067,2049,2027,2025,2067,2079,2055,2057,2073,2053,2019,2057,2029,2061,2051,2031,2065,2065,2025,2061,2011,2041,2053,2033,2061,2065,2023,2029,2053,2031,2009,2021,2027,2035,2029,2021,2027,2043,2051,2043,2065,2025,2061,2053,2069,2005,2081,2057,2007,2037,2065,2065,2039,2029,2027,2035,2041,2097,2033,2083,2053,2027,2055,2067,2055,2029,2029,2049,2021,2025,2053,2057,2027,2069,2061,2029,2037,2039,2035,2005,2035,2077,2057,2049,2007,2033,2059,2059,2015,2065,2067,2013,2031,2009,2059,2073,2033,2057,2041,2059,2051,2031,2043,2019,2033,2039,2051,2087,2043,2049,2051,2051,2033,2049,2055,2065,2041,2085,2035,2069,2061,2101,2023,2023,2053,2051,2037,2039,2077,2073,2043,2037,2057,2063,2073,2043,2075,2065,2049,2011,2061,2031,2061,2055,2031,2017,2071,2069,2049,2037,2103,2031,2055,2049,2023,2053,2065,2035,2033,2075,2067,2029,2017,2049,2081,2055,2051,2055,2049,2071,2043,2055,2057,2053,2041,2065,2055,2049,2033,2033,2051,2017,2051,2037,2023,2093,2053,2049,2025,2021,2057,2033,2021,2007,2051,2057,2029,2009,2041,2105,2063,2061,2033,2011,2083,2033,2015,1993,2065,2039,2055,2029,2043,2037,2025,2041,2055,2025,2105,2053,2011,2069,2065,2043,2041,2051,2037,2049,2017,2041,2065,2067,2057,2053,2077,2053,2035,2055,2067,2043,2035,2079,2043,2055,2033,2053,2083,2065,2049,2049,2029,2055,2027,2065,2071,2079,2027,2031,2021,2031,2055,2071,2033,2057,2057,2029,2017,2051,2057,2043,2049,2037,2071,2039,2067,2071,2031,2029,2039,2007,2027,2067,2037,2041,2061,2053,2059,2085,2019,2065,2015,2031,2029,2063,2061,2049,2063,2015,2053,2027,2017,2057,2059,2049,2067,2065,2059,2039,2055,2007,2019,2043,2041,2115,2033,2069,2031,2079,2057,2031,2051,2067,2013,2073,2023,2049,2065,2025,2023,2057,2039,2059,2049,2029,2039,2031,2045,2037,2017,2057,2035,2025,2053,2007,2039,2067,2037,2073,2031,2035,2055,2055,2033,2025,2041,2041,2027,2037,2039,2023,2077,2015,2029,2051,2039,2039,2055,2075,2035,2029,2027,2065,2061,2043,2057,2025,2011,2051,2065,2033,2029,2033,2039,2031,2051,2055,2037,2053,2015,2061,2019,2051,2069,2053,2057,2053,2061,2057,2021,2033,2063,2035,2051,2039,2029,2069,2035,2019,2035,2043,2041,2053,2061,2055,2071,2041,2033,2041,2041,2061,2053,2027,2029,2085,2037,2059]}
{"Q":[2061,2043,2051,2053,2057,2035,2029,2051,2049,2035,2043,2029,2053,2043,2041,2051,2053,2035,2049,2041,2053,2053,2037,2037,2067,2039,2061,2037,2033,2037,2035,2033,2059,2039,2041,2043,2039,2033,2053,2035,2053,2033,2039,2041,2055,2043,2051,2041,2033,2053,2043,2039,2039,2057,2049,2051,2059,2067,2037,2049,2023,2057,2055,2035,2043,2049,2037,2055,2039,2039,2065,2041,2063,2039,2057,2055,2041,2043,2037,2051,2041,2051,2039,2053,2057,2027,2041,2053,2055,2053,2041,2053,2057,2049,2031,2051,2061,2039,2057,2053,2057,2027,2037,2061,2059,2037,2057,2055,2059,2037,2049,2035,2059,2043,2029,2057,2059,2057,2057,2057,2029,2053,2051,2043,2055,2041,2057,2051,2061,2057,2029,2051,2041,2051,2061,2043,2061,2041,2049,2051,2059,2035,2055,2033,2051,2031,2041,2053,2059,2039,2041,2059,2061,2033,2043,2051,2041,2051,2063,2031,2041,2041,2041,2049,2049,2057,2041,2043,2053,2043,2061,2033,2055,2057,2073,2039,2041,2053,2053,2031,2039,2041,2049,2015,2033,2051,2053,2037,2051,2057,2069,2057,2037,2027,2043,2031,2053,2043,2037,2041,2031,2041,2057,2031,2043,2043,2039,2029,2039,2039,2033,2059,2063,2037,2029,2051,2055,2035,2037,2039,2039,2043,2021,2035,2053,2063,2029,2037,2031,2049,2053,2053,2029,2037,2057,2037,2031,2035,2043,2039,2053,2041,2031,2041,2049,2039,2025,2043,2053,2037,2027,2039,2051,2071,2057,2029,2055,2039,2037,2049,2057,2033,2035,2035,2053,2037,2057,2049,2049,2051,2061,2027,2057,2037,2059,2057,2035,2053,2057,2053,2055,2029,2061,2051,2055,2033,2031,2027,2055,2039,2029,2037,2061,2067,2041,2033,2039,2051,2051,2027,2059,2033,2051,2059,2017,2041,2061,2041,2055,2053,2057,2041,2053,2053,2059,2055,2037,2037,2049,2039,2035,2041,2057,2037,2037,2037,2053,2041,2051,2051,2043,2035,2041,2035,2053,2049,2051,2051,2043,2041,2053,2041,2059,2051,2051,2049,2041,2051,2039,2059,2049,2057,2069,2035,2057,2049,2055,2033,2025,2051,2041,2033,2065,2041,2061,2061,2055,2051,2055,2043,2055,2027,2037,2043,2061,2037,2057,2033,2059,2037,2051,2059,2051,2061,2051,2035,2055,2043,2055,2037,2035,2055,2053,2037,2049,2065,2075,2053,2053,2029,2039,2029,2053,2049,2059,2035,2035,2041,2053,2039,2059,2037,2057,2057,2053,2051,2043,2049,2061,2051,2059,2049,2055,2041,2065,2037,2059,2057,2037,2037,2027,2031,2061,2049,2049,2025,2051,2037,2049,2049,2049,2039,2053,2037,2043,2041,2051,2061,2057,2049,2049,2049,2049,2041,2049,2057,2061,2049,2039,2051,2053,2053,2053,2041,2043,2041,2055,2027,2067,2053,2057,2039,2051,2043,2063,2051,2061,2041,2051,2039,2059,2049,2041,2057,2049,2051,2041,2053,2039,2035,2057,2041,2059,2041,2051,2057,2051,2035,2051,2049,2039,2059,2055,2039,2067,2049,2041,2053,2069,2029,2051,2043]}

Respuestas (1)

Walter Roberson
Walter Roberson el 16 de Dic. de 2021
I = {}; Q = {};
idx = 0;
last_was_I = false;
%assume you have just read one line into inputline
isI = inputline(3) == "I";
values = str2double(regexp(inputline(6:end-2), ',', 'split'));
if isI
if last_was_I
%two I in a row. Let the new one overwrite the old data
else
idx = idx + 1;
end
I{idx} = values(:);
last_was_I = true;
else
if last_was_I
Q{idx} = values(:);
last_was_I = false;
else
%This is a Q not immediately following an I; skip it
end
end
This uses a small state machine, to account for these factors to try to store only I+Q pairs:
  • skip leading Q before any I
  • if you get two I in a row then assume a Q went missing. Let the new I overwrite the previous data
  • If you get two Q in a row then assume an I went missing. Do not store this one
Note: when you somehow detect end of input, then if last_was_I is true, you need to discard the newest stored I value, as there was no corresponding Q value found for it.
  2 comentarios
MUHAMMAD ARIF ROSLI
MUHAMMAD ARIF ROSLI el 17 de Dic. de 2021
Thanks for response,
I already try the new code but the problem is it only store the last data, I want to store all the data.
This is my code:
%
close all; clear all;
% serial object
s = serial('COM5', 'BaudRate', 9600, 'DataBits', 8, 'Parity', 'none',...
'StopBits', 1, 'FlowControl', 'none', 'InputBufferSize', 65536,...
'Terminator', 'CR');
s.ReadAsyncMode = 'continuous';
% open serial port
fopen(s);
% Read command to active doppler raw data
fprintf(s,'%s','OR')
while (1)
a = fscanf(s)
o = eraseBetween(a,"{","I");
l = eraseBetween(o,"I",":");
k = eraseBetween(l,"{","Q");
u = eraseBetween(k,"{","R");
y = eraseBetween(u,"R","}");
a = eraseBetween(y,"Q",":");
b = erase(a,"{");
c = erase(b,"I");
d = erase(c,":");
e = erase(d,"[");
f = erase(e,"]");
g = erase(f,"}");
h = erase(g,"Q");
z = erase(h,"R")
vec = split(z,',');
vec = str2double(vec);
end
a is the real output that I mention in the question before,
z is the output that I already filter part that I dont want, but the problem is this code only store the last data of Q.
Can you help me?
Thanks again.
Walter Roberson
Walter Roberson el 17 de Dic. de 2021
That is certainly not my code.
At the end of the loop, you need to save vec, such as
saved_vec{end+1} = vec;
I notice that your code processes R records as well; those were not shown in the example data. It looks to me as if you are ignoring that data, though ?

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by