Hello!
Be
Z={'1.1 2.1 3.2 3.3 5.5 5.4'; '3 4 5 10 11 56'};
a 2*1 cell array.How can I split Z into a cell array with 2x6 cells? Notice that Z is composed by numbers.
Thanks a lot.

 채택된 답변

Stephen23
Stephen23 2016년 4월 25일
편집: Stephen23 2016년 4월 25일

2 개 추천

Option One: Convert to Numeric
>> mat = [sscanf(Z{1},'%f'),sscanf(Z{2},'%f')].'
mat =
1.1000 2.1000 3.2000 3.3000 5.5000 5.4000
3.0000 4.0000 5.0000 10.0000 11.0000 56.0000
Best would be to leave it as a numeric array... however if you really need a cell array of numeric scalars, then use num2cell:
num2cell(mat)
Option Two: Keep as String
>> tmp = regexp(Z,'\S+','match');
>> tmp = vertcat(tmp{:})
tmp =
'1.1' '2.1' '3.2' '3.3' '5.5' '5.4'
'3' '4' '5' '10' '11' '56'

댓글 수: 4

angelavtc
angelavtc 2016년 4월 25일
편집: angelavtc 2016년 4월 25일
Dear stephen
Actually my cell array is of size 10*1 cell and it goes like this:
[199001031001.000;199001031006.000;199001031011.000] [199001031002.000;199001031007.000;199001031012.000] [199001031003.000;199001031008.000;199001031013.000] [199001031004.000;199001031009.000;199001031014.000] [199001031005.000;199001031010.000;199001031015.000]
[199001031006.000;199001031011.000]
[199001031007.000;199001031012.000]
[199001031008.000;199001031013.000]
[199001031009.000;199001031014.000]
[199001031010.000;199001031015.000]
is there a way to decompose it and have each of its elements in one cell?
angelavtc
angelavtc 2016년 4월 25일
Becase when I use your code it says "Error using regexp All cells must be strings" which makes sense because they are not actually strings but numbers. Can you help me to solve this problem?
Thanks a lot
Stephen23
Stephen23 2016년 4월 26일
편집: Stephen23 2016년 4월 26일
@angelavtc: That example with numeric vectors inside a cell array cannot be trivially converted to a single array with each numeric element in its own cell, because you have different number of elements in each vector. You could try experimenting with these FEX submissions:
Note that you can supply the contents of a cell array by using a comma separated list:
inp = {[...],[...]}
out = padcat(inp{:})
angelavtc
angelavtc 2016년 4월 30일
Thanks a lot!!!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2016년 4월 25일

댓글:

2016년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by