cell of characters to column

조회 수: 2 (최근 30일)
Arvind Gauns
Arvind Gauns 2022년 5월 16일
댓글: dpb 2022년 5월 17일
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
Jan
Jan 2022년 5월 16일
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 2022년 5월 17일
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

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2022년 5월 16일
편집: dpb 2022년 5월 16일
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'}
>>

추가 답변 (1개)

Voss
Voss 2022년 5월 16일
편집: Voss 2022년 5월 16일
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
Arvind Gauns
Arvind Gauns 2022년 5월 17일
Thanks. It was very comprehensive and informative
dpb
dpb 2022년 5월 17일
@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???

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by