Convert 1x1 cell to 1x1 double

19 Ansichten (letzte 30 Tage)
Shrinish Donde
Shrinish Donde am 18 Jan. 2021
Bearbeitet: Mario Malic am 19 Jan. 2021
Hi,
I am trying to convert a 1x1 cell to 1x1 double using str2double. An explanation is as follows:
M.c = str2double(T(test, x))
M: 1x1 struct with a field c
T: table
test: row number in T
x: column number in T
Matlab version: R2020b
PS: The individual values in (test,x) are of type double but since they are inside a table they are converted to 1x1 cell type and therefore I have to convert it to 1x1 double array.
Problem: I am getting 'NaN' when I try to set the value of M.c. I am expecting a double to be set there since the program is structured in that way.
Thank you.
  1 Kommentar
dpb
dpb am 18 Jan. 2021
Attach a small subset of the table T as .mat file...we can't see the needed details from here.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mario Malic
Mario Malic am 18 Jan. 2021
Bearbeitet: Mario Malic am 19 Jan. 2021
Hi, depending on the contents in the cell array, here are two examples. Mind the indexing into cell, you should use curly brackets to get the "contents" of the cell.
% Example for a character array with single element
a = '3.4';
str2num(a)
ans =
3.4000
str2double(a)
ans =
3.4000
% Example for character array with multiple elements
a ='3.4, 5.2';
str2double(a)
ans =
NaN
str2num(a)
ans =
3.4000 5.2000

Weitere Antworten (0)

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