Saving workspace variables into rows of a table

조회 수: 18 (최근 30일)
Aliki Papoutsi
Aliki Papoutsi 2022년 3월 29일
답변: Siddharth Bhutiya 2022년 4월 5일
Hello,
I am running a user input function, where the user enters multiple codes in a text box. Each code has the form "04 11 70 32 24 6d 80", and the clock generates a date and time of this action. Everytime the user inputs the codes, they are made into a cell array named 'x' in the workspace (along with the clock data, named 'c'). How can I save each version of the codes cell array and clock into a table everytime they change?

답변 (2개)

Shivam Singh
Shivam Singh 2022년 4월 1일
Hello Aliki,
It is my understanding that you want to convert workspace variables into a table.
You may refer the following links for doing so:

Siddharth Bhutiya
Siddharth Bhutiya 2022년 4월 5일
Since you are working with timestamped data it would be better to use timetables instead of tables. With timetable you can simply start with an empty timetable, and then use tt.Var(idx) syntax to keep adding values as shown below
>> tt = timetable
tt =
0×0 empty timetable
>> x = {"aa bb cc"}
x =
1×1 cell array
{["aa bb cc"]}
>> c = datetime
c =
datetime
05-Apr-2022 16:10:08
>> tt.Codes(c) = x
tt =
timetable
Time Codes
____________________ ______________
05-Apr-2022 16:10:08 {["aa bb cc"]}
>> x = {"aa1 bb2 cc3"};
>> c = datetime;
>> tt.Codes(c) = x
tt =
2×1 timetable
Time Codes
____________________ _________________
05-Apr-2022 16:10:08 {["aa bb cc" ]}
05-Apr-2022 16:10:21 {["aa1 bb2 cc3"]}

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by