how to extract the big content of a cell array?

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

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.
@Stephen Cobeldick Yeah you are right I should have given the data. The whole file is too big to import so I selected just 3 cells.
@VBBV I have already tried but I get
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Guys, I have found this solution. Anyway if you a better code....
S= importdata('data.csv');
B = S_1{1};
A = convertCharsToStrings(B);
C= extract(A,digitsPattern);
v=str2double(C)';
@Valeria Leto: the file you uploaded here is a .mat file with a .csv extension. Please upload your original data file.
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.
@Stephen Cobeldick @Image Analyst Unfortunately I don't know how these data were stored. The file was given to me like this. Maybe the person who gave me the data wanted to test me ahahhah. I know the file is a mess, in fact I panicked when I first saw it!
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')
ans = datetime
29-Mar-2021 14:01:19
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
"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.

Sign in to comment.

Answers (0)

Categories

Asked:

on 5 Aug 2021

Commented:

on 10 Aug 2021

Community Treasure Hunt

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

Start Hunting!