How to concatenate an array?

조회 수: 1 (최근 30일)
Luis Ricardo Rivera Goitia
Luis Ricardo Rivera Goitia 2023년 3월 29일
댓글: Luis Ricardo Rivera Goitia 2023년 4월 10일
I have an array that is receiving data from the cloud, and I'm loosing the initial data while the array continue receiving the data.
How can I concatenate the data to keep the initial data in the array while continue receiving new data?
Here's the code and the array as a reference.
while true
dataTT = (read(MQTTSignal));
str = dataTT.Data;
str = strrep(str, '{', ''); % remove opening bracket
str = strrep(str, '}', ''); % remove closing bracket
str = split(str,",");
current = str2double(str(:,1));
speed = str2double(str(:,2));
time = str2double(str(:,3));
subplot(2,1,1);
plot(time,current);
ylim([0,150]);
grid ON
title("Current");
subplot(2,1,2);
plot(time,speed);
ylim([0,1000]);
grid ON
title("Speed");
drawnow
pause(3)
end

채택된 답변

Matt J
Matt J 2023년 3월 29일
dataTT=[];
while true
dataTT = [dataTT, read(MQTTSignal)];
str = dataTT(end).Data;
...
end
  댓글 수: 7
Matt J
Matt J 2023년 3월 31일
dataTT = [dataTT, table2struct( read(MQTTSignal) ,"ToScalar",1 )];
Luis Ricardo Rivera Goitia
Luis Ricardo Rivera Goitia 2023년 4월 10일
Apparently it worked, the only thing is that dataTT is now divided in two, and one of this two is cumulating the data in segments, I think that would help me to avoid loosing the previous information, thx.
Here's an image about its behavior:
As you can see Data column is storing the dataTT received from MQTT in segments.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by