How to convert cell 2 double?

59 ビュー (過去 30 日間)
Mira le
Mira le 2019 年 12 月 8 日
編集済み: dpb 2019 年 12 月 8 日
>> U=SI
U =
1×2 cell array
[1×2 double] [1×2 double]
>> U{1}
ans =
1 2
>> U{2}
ans =
2 3
>> sitem=[]
sitem =
[]
>> class(sitem)
ans =
'double'
I want to copy each cell of U in sitem which sitem remain double class
  6 件のコメント
dpb
dpb 2019 年 12 月 8 日
You've apparently gotten cell arrays embedded in cell arrays...we'll then have to see just what you actually have to know how many levels of dereferencing it'll take. Or, better yet, remove one or more unecessary levels.
As starters, though, what does
whos SI U
return? And, for good measure, just
SI
at the command line?
In addition, show us the code that creates SI.
Mira le
Mira le 2019 年 12 月 8 日
SI is cell array
SI
SI =
1×2 cell array
[1×2 double] [1×2 double]
sitem should be doule , and each time sitem has one value of SI or all value of SI
like that;
sitem= unique([U{:}])

サインインしてコメントする。

回答 (1 件)

dpb
dpb 2019 年 12 月 8 日
編集済み: dpb 2019 年 12 月 8 日
If SI is as you say...
>> SI={rand(1,2) rand(1,2)}
SI =
1×2 cell array
{1×2 double} {1×2 double}
>> sitem=cell2mat(SI)
sitem =
0.7150 0.9037 0.8909 0.3342
>>
then cell2mat does the dirty of the original question of returning array of all elements of SI.
You didn't say nothing about no unique() being anywhere in the picture before, altho it's unclear it has any bearing on the question asked.
The "{:}" idiom/syntax returns a comma-separated list of the elements in the cell array, hence requiring the [] to catenate together as argument. Either is OK, cell2mat is probably somewhat more efficient than [].
NB: Either will run into problems if the sizes of the cell arrays are disparate in dimensions as both are a catenation operation.
In the end, it isn't fully clear what the actual question really was/is...

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by