Storing data in a real time recording gui using a callback
Mostrar comentarios más antiguos
Hi,
I have created a GUI to read wavelength data from FBG fibers and reconstruct their shape in real time. To read, I use a TCPIP connection and a callback implemented with a terminatror. This terminator just throws an event when the new-line character is present in the data:
h = animatedline(app.UIAxes);
app.tcpFBG.BytesAvailableFcn = {@readingData,app,h};
app.tcpFBG.BytesAvailableFcnMode = 'Terminator';
app.tcpFBG.Terminator = 'LF';
In the callback "readingData" I read the data from the buffer, reconstruct the shape, store the data and plot the shape of the fibers
function data = readingData(connection,~,app,h)
tic
clearpoints(h)
data = fscanf(connection);
[EngineeredValues,PeakWavelengths,~] = app.fbg.readingData(data);
[shape,curv,curvDir] = app.fbg.reconstruct(EngineeredValues,PeakWavelengths);
app.pushShapeData(shape); %Saving the data in app.shapeData
app.pushCurvData(curv); %Saving the data in app.curvData
app.pushCurvDirData(curvDir); %Saving the data in app.curvDirData
addpoints(h,shape(1,:),shape(2,:),shape(3,:))
toc
end
The functions used to add the read data with data from previous samples is:
function pushShapeData(app,shape)
app.shapeData = cat(3,app.shapeData,shape);
end
function pushCurvData(app,curv)
app.curvData = cat(3,app.curvData,curv);
end
function pushCurvDirData(app,curvDir)
app.curvDirData = cat(3,app.curvDirData,curvDir);
end
I guess this way of storing the data is not efficient, and as the amount of data increases, this operation becomes slower. This problem makes my reconstruction and plotting laggy for long reading times, but as you can see, I don't know the total amount of data to be save because it depends on when the user stops the recording. Is there any efficient way to concatenate these array and store the data efficiently? Thank you in advance.
3 comentarios
Mohammad Sami
el 1 de Feb. de 2020
Have you tried profiling. Which functions are taking the longest ?
Carlos Fambuena
el 1 de Feb. de 2020
Carlos Fambuena
el 1 de Feb. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!