how to extract the big content of a cell array?
Show older comments
Hi! I have a 2859x1 cell array. In each cell there is a content like this:
1617026479572040798,,0,,0,0,'',25.0,,,[],0,"[76, 74, 71, 78, 76, 77, 73, 76, 73, 76, 79, 154, 158, 164, 166, 149, 134, 137, 131, 124, 123, 121, 114, 121, 117, 109, 120, 117, 115, 106, 104, 110, 111, 116, 116, 114, 109, 115, 114, 110, 106, 113, 109, 114, 114, 113, 118, 107, 110, 109,.....
I would like to save the numbers it into a double array. How could I do that? Thanks
11 Comments
VBBV
on 5 Aug 2021
cell2mat functìon
" I have a 2859x1 cell array."
If that data was imported from a file then you should really just fix the file importing, rather than fiddle around with strings afterwards.
Please upload an original sample that we can work with, by clicking the paperclip button.
Valeria Leto
on 6 Aug 2021
Valeria Leto
on 6 Aug 2021
Valeria Leto
on 6 Aug 2021
Image Analyst
on 6 Aug 2021
I totally agree with Stephen. How did this mat file get created in the first place and why was the variable stored in it so messed up to begin with? Let's just work on saving the data correctly rather than try to fix up a complicated mess of a file.
Valeria Leto
on 8 Aug 2021
The .mat file you attached had an incomplete S{3} cell.
You might be interested to note that the first column is a Posix time in nanoseconds
datetime(1617026479572040798/1e9, 'convertfrom', 'posixtime')
Peter Perkins
on 9 Aug 2021
The problem is that once you type 1617026479572040798, you are already done for:
>> sprintf("%.20f",1617026479572040798)
ans =
"1617026479572040704.00000000000000000000"
If it's wrapped in uint64, things are OK,
>> uint64(1617026479572040798)
ans =
uint64
1617026479572040798
but then the question is how to get that into a datetime with as much precision as possible. The solution is epochtime:
>> datetime(uint64(1617026479572040798), 'convertfrom', 'epochtime','TicksPerSecond',1e9,'Epoch','1-Jan-1970','Format','dd-MMM-uuuu HH:mm:ss.SSSSSSSSS')
ans =
datetime
29-Mar-2021 14:01:19.572040798
Stephen23
on 10 Aug 2021
"Unfortunately I don't know how these data were stored. The file was given to me like this."
This contradicts your statement that "The whole file is too big to import so I selected just 3 cells."
Please upload an original file as requested. Do not upload data that you have already imported into MATLAB.
If the original file is too large to upload onto the forum, please shorten it whilst keeping its format representative.
Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!