convert from cell array to double

18 次查看(过去 30 天)
b =
1×1 cell array
{1×2 cell}
i want to get last element in cell ("4") and convert it in double

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-9-3
Use indexing -
%Assuming this is how your data is stored
b = {{6,4}}
b = 1×1 cell array
{1×2 cell}
c = b{1}{2}
c = 4

更多回答(1 个)

Abderrahim. B
Abderrahim. B 2023-9-3
Hi!
Use patentheses () if you want the output to be a cell
myCell = {42, rand(5)}
myCell = 1×2 cell array
{[42]} {5×5 double}
ele = myCell(1,2)
ele = 1×1 cell array
{5×5 double}
Use curly parentheses to get data from the cell in its type
ele = myCell{1,2}
ele = 5×5
0.5062 0.9224 0.3035 0.3201 0.1839 0.8434 0.3387 0.2509 0.9461 0.0362 0.7808 0.7764 0.8302 0.8172 0.1848 0.4092 0.3476 0.0203 0.6906 0.3348 0.1126 0.0982 0.7486 0.7783 0.4946
You can also try cell2mat with the first approach to convert cell to array of double..
myCell = {42, rand(5)}
myCell = 1×2 cell array
{[42]} {5×5 double}
ele = cell2mat(myCell(1,2))
ele = 5×5
0.8558 0.6122 0.0712 0.3533 0.1033 0.5384 0.4733 0.2903 0.4612 0.7655 0.9834 0.4619 0.2614 0.7796 0.3795 0.4509 0.1652 0.7384 0.5678 0.7921 0.8444 0.0822 0.0433 0.8701 0.6699
Hope this helps
Abderrahim

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by