convert from cell array to double

13 Ansichten (letzte 30 Tage)
pipor
pipor am 3 Sep. 2023
Beantwortet: Abderrahim. B am 3 Sep. 2023
b =
1×1 cell array
{1×2 cell}
i want to get last element in cell ("4") and convert it in double

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 3 Sep. 2023
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

Weitere Antworten (1)

Abderrahim. B
Abderrahim. B am 3 Sep. 2023
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

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by