cell of characters to column

1 view (last 30 days)
Arvind Gauns
Arvind Gauns on 16 May 2022
Commented: dpb on 17 May 2022
I have a cell of 1*3430 character consisting of acqusition time for 245 files. (one time value is of 14 charachters stored in continuous manner).
i want to convert it into a column. i tried using trim function but there was some error everytime.
these values would be input to another function so getting these values are essential hence looking for help in this regards.
  2 Comments
Jan
Jan on 16 May 2022
The question is not clear:
  1. What is a "cell of 1*3430 character"?
  2. What does "acqusition time for 245 files" exactly mean?
  3. What is "stored in continuous manner"?
  4. What is the type and size after "convert it into a column"?
  5. With which code did you try the trim function?
  6. What was the error message?
Please post more details.
Arvind Gauns
Arvind Gauns on 17 May 2022
I tried was using some tutorials which i am not able to access. Due to privacy of the dataset, I couldnt reweal the details but thanks for the response. the query is resolved

Sign in to comment.

Accepted Answer

dpb
dpb on 16 May 2022
Edited: dpb on 16 May 2022
We need to see this in situ -- how did you get it into such a form, first.
Attach the file from whence the data came (or a representative sample thereof) and/or a .mat file of the data.
While it's probably possible to avoid having to do so by reading the data in correctly, if they are fixed-length strings, then
t=cellstr(reshape(s,14,[]).');
will give you an Nx14 cellstr array to pass or convert.
Example, dummy data--
>> s='A':'z'; s=s(1:end-2) % make up a string with mod(14) characters...
s =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwx'
>> strlength(s)
ans =
56
>>
Apply the engine...
>> t=cellstr(reshape(s,14,[]).')
t =
4×1 cell array
{'ABCDEFGHIJKLMN'}
{'OPQRSTUVWXYZ[\'}
{']^_`abcdefghij'}
{'klmnopqrstuvwx'}
>>

More Answers (1)

Voss
Voss on 16 May 2022
Edited: Voss on 16 May 2022
It's not clear whether you have (Case 1) a cell array of characters, like this:
times_cell_char = {'0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '2' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '3' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '4'}
times_cell_char = 1×70 cell array
{'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'1'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'2'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'3'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'0'} {'4'}
Or (Case 2) a cell array of character vectors, like this:
times_cell = {'00000000000000' '00000000000001' '00000000000002' '00000000000003' '00000000000004'};
Or (Case 3) a single character vector, like this:
times_char = '0000000000000000000000000001000000000000020000000000000300000000000004';
It's also not clear what you want the result to be.
If the result should be a character array, you can do one of these things:
Case 1:
times = reshape([times_cell_char{:}],14,[]).'
times = 5×14 char array
'00000000000000' '00000000000001' '00000000000002' '00000000000003' '00000000000004'
Case 2:
times = char(times_cell.')
times = 5×14 char array
'00000000000000' '00000000000001' '00000000000002' '00000000000003' '00000000000004'
Case 3:
times = reshape(times_char,14,[]).'
times = 5×14 char array
'00000000000000' '00000000000001' '00000000000002' '00000000000003' '00000000000004'
If the result should be a (column) cell array of character vectors, you can do one of these things:
Case 1:
times = cellstr(reshape([times_cell_char{:}],14,[]).')
times = 5×1 cell array
{'00000000000000'} {'00000000000001'} {'00000000000002'} {'00000000000003'} {'00000000000004'}
Case 2:
times = times_cell.'
times = 5×1 cell array
{'00000000000000'} {'00000000000001'} {'00000000000002'} {'00000000000003'} {'00000000000004'}
Case 3:
times = cellstr(reshape(times_char,14,[]).')
times = 5×1 cell array
{'00000000000000'} {'00000000000001'} {'00000000000002'} {'00000000000003'} {'00000000000004'}
  2 Comments
Arvind Gauns
Arvind Gauns on 17 May 2022
Thanks. It was very comprehensive and informative
dpb
dpb on 17 May 2022
@Arvind Gauns, I'd still ask/am curious how you got such data into such a format in the beginning so that you had to split it this way. It would seem could avoid that in the beginning???

Sign in to comment.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!