How to build and call an array of objects containing a table of data
2 views (last 30 days)
Show older comments
Hi everyone
I'm constructing an Object containing all the data of a test.
So i construct the object passign an excel file with my data. The object is then composed by various arrays and parameters like TestID, date, dataArray1, dataArray2...
Then I want to create an "array" with all these object. I would imagine to call it like:
Test(1)
Test(2)
Test(3)
So that at every index i have an object containing alla the data of my test.
Is this possible to do? If not, which would be the more similar solution to my issue?
Thanks
Accepted Answer
dpb
on 18 Feb 2021
How about something like
test=timetable(datetime(2020,2,13+[0;sort(randi(20,4,1))]),randi([120 240],5,1),'VariableNames',{'Temperature'})
test.Data=mat2cell(rand(5*24,1000),24*ones(5,1),1000);
results in a format llike
>> test
test =
5×2 timetable
Time Temperature Data
___________ ___________ ________________
13-Feb-2020 238 {24×1000 double}
21-Feb-2020 164 {24×1000 double}
28-Feb-2020 185 {24×1000 double}
28-Feb-2020 198 {24×1000 double}
01-Mar-2020 139 {24×1000 double}
>>
which would let address the time by either the date itself or row number and the table would let you do something like
maxT=rowfun(@(x)max(x{:}),test,'InputVariables','Data','OutputVariableNames','MaxTemp')
>> maxT=rowfun(@(x)max(x{:}),test,'InputVariables','Data','OutputVariableNames','MaxTemp')
maxT =
5×1 timetable
Time MaxTemp
___________ _______________
13-Feb-2020 [1×1000 double]
21-Feb-2020 [1×1000 double]
28-Feb-2020 [1×1000 double]
28-Feb-2020 [1×1000 double]
01-Mar-2020 [1×1000 double]
>>
A small subset of which is
>> maxT.MaxTemp(1:5,1:10)
ans =
0.9369 0.8806 0.9299 0.9926 0.9803 0.9308 0.9842 0.9998 0.9572 0.9930
0.9224 0.9566 0.9909 0.9890 0.9767 0.9953 0.9402 0.9408 0.9469 0.9996
0.9843 0.9603 0.8832 0.9348 0.9770 0.9242 0.9784 0.9829 0.9511 0.9644
0.9831 0.9341 0.8840 0.9254 0.9678 0.9834 0.9797 0.9551 0.9628 0.9704
0.9238 0.9933 0.9223 0.9906 0.9106 0.9145 0.9468 0.9897 0.9685 0.9525
>>
If had other test conditions, would also be suitable to use those as grouping variables or whatever; one can write the functions to return what is wanted; above could have used the 'all' option to get an overall mean instead of column or the dimension 2 for what is presumed to be hourly readings.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!