I think your problem is that the output from regexp is a cell array of cell arrays of strings (i.e. two levels of cell encapsulation), but you want it to be a cell array of strings. You can achieve that by adding the 'once' option to the call to regexp. Then you will get a cell array of strings that can be passed to str2double:

>> P = {'Rock_1', 'Rock_2', 'Rock_3'};  % Sample data
>> Rocks = regexp(P, '\d*', 'match');   % How you did it above
>> str2double(Rocks)

ans =

   NaN   NaN   NaN

>> Rocks = regexp(P, '\d*', 'match', 'once');  % With the 'once' option
>> str2double(Rocks)

ans =

     1     2     3
Answer from gnovice on Stack Overflow
🌐
MathWorks
mathworks.com › matlabcentral › answers › 428432-why-am-i-returning-nan-with-str2double
Why am I returning NaN with str2double? - MATLAB Answers - MATLAB Central
November 7, 2018 - For anyone else confused by this function, str2double(x) for some reason returns "NaN" if x is a double. This doesn't match the behavior of any programming language I'm familar with.
🌐
Northwestern University
ece.northwestern.edu › local-apps › matlabhelp › techdoc › ref › str2double.html
str2double (MATLAB Functions)
X = str2double('str') converts ... a leading + or - sign, an e preceeding a power of 10 scale factor, and an i for a complex unit. If str does not represent a valid scalar value, str2double returns NaN....
🌐
MathWorks
mathworks.com › matlabcentral › answers › 616058-nan-from-str2double-1-2-3-on-matlab-2020a
NaN from str2double('1 2 3') on Matlab 2020a - MATLAB Answers - MATLAB Central
October 16, 2020 - Hi str2double('1 2 3') returns NaN on Matlab 2020a but works fine on Matlab 2018b & Matlab 2016b (returns: 1 2 3). How to convert a string of numbers to numbers in the newest Matlab version? ...
Top answer
1 of 1
2
The reason for the observed behavior is the stdio library used by Arduino. The code generated by str2double uses a function called sscanf. This function internally calls vfscanf function. vfscanf is available in three different versions. Out of these three versions, the default version does not implement scanning float variables. This is mentioned in the doc: "By default, all the conversions described above are available except the floating-point conversions and the width is limited to 255 characters. The float-point conversion will be available in the extended version provided by the library libscanf_flt.a. Also, in this case the width is not limited (exactly, it is limited to 65535 characters). To link a program against the extended version, use the following compiler flags in the link stage: -Wl,-u,vfscanf -lscanf_flt -lm " Refer the following doc link for more details: https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga67bae1ad3af79809fd770be392f90e21 To use compiler flags mentioned in the doc, you can follow the steps mentioned below: 1. Open config set 2. Go to "Code Generation" tab 3. In "Build configuration" drop down, select "Specify" 4. In C++ Liker, append the following: -Wl,-u,vfscanf -lscanf_flt -lm 5. Dont forget to add a space to the existing flags before appending the new flags. 6. Click apply, OK. 7. Run the model in external mode. Please note that using the extended version of this library will consume a lot of code space.
Find elsewhere
🌐
MATLAB
matlab.izmiran.ru › help › techdoc › ref › str2double.html
str2double (MATLAB Functions)
X = str2double('str') converts ... a leading + or - sign, an e preceding a power of 10 scale factor, and an i for a complex unit. If str does not represent a valid scalar value, str2double returns NaN....
🌐
MathWorks
mathworks.com › matlabcentral › answers › 242521-problem-using-str2num-str2double
Problem using str2num/str2double - MATLAB Answers - MATLAB Central
September 12, 2015 - https://www.mathworks.com/matlabcentral/answers/242521-problem-using-str2num-str2double#comment_310122 ... Thanks for the reply. Basically, I am using a .m file to process the output results at nodes and in elements. Str2num function has been used to covert the string into number. That file is working with smaller amount of load, i.e. 200. The same file was not working for 1000 or 1000s load. I changed str2num to str2double, the file run. However, I was getting all NaN values.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1976434-why-does-str2double-command-return-nan-what-type-of-array-should-i-convert-into-for-running-fitlm-c
Why does str2double command return NaN? What type of array should I convert into for running fitlm command?? - MATLAB Answers - MATLAB Central
May 31, 2023 - In the first place, I tried str2double but it returned only 48 NaNs. I tried to cell2mat but it didn't work either. What command should I use for running fitlm? Sign in to comment. Sign in to answer this question. ... https://www.mathworks.com/matlabcentral/answers/1976434-why-does-str2double-command-return-nan-what-type-of-array-should-i-convert-into-for-running-fitlm-c#answer_1247974
🌐
MathWorks
mathworks.com › requirements toolbox › author and validate requirements › model and validate requirements
str2double - Convert string to double-precision value in Requirements Table block - MATLAB
X = str2double(str) converts the text in string str to a double-precision complex value. If str2double cannot convert the text to a number, it returns a NaN value.
🌐
Narkive
octave-bug-tracker.gnu.narkive.com › f5uncoZe › wrong-handling-of-missing-values-by-str2double
Wrong handling of missing values by str2double
Permalink On 29-Jan-2008, Olivier Lefevre wrote: | I think that str2double tokenizes the line incorrectly: it simply | jumps over the empty slots, e.g, str2double("3.4,,3.2") return | [3.4, 3.2]. The man page for that function is actually mum on what | happens in that case. I would prefer that it be treated as a bug | but if not, at least this behaviour should be documented. What would you expect it to do? It seems that the current behavior is not compatible with Matlab (it returns NaN for the above or even str2double ("3.4, 3.2").
🌐
MathWorks
mathworks.com › matlabcentral › answers › 893897-error-using-str2double-on-a-cell-array-getting-nan
Error using str2double on a cell array, getting NaN - MATLAB Answers - MATLAB Central
August 6, 2021 - As per the image you attached, the format of the date/time is dd/mm/yyyy hh:mm. As per the documentation of str2double , if str2double cannot convert text to a number, then it returns a NaN value which could be cause of the error you are facing
🌐
Abeysuriya
abeysuriya.com › 2011 › 11 › 01 › matlab-str2num-str2double.html
MATLAB - str2num() vs str2double()
November 1, 2011 - There is one catch though- if you are converting a single number from a string to a number, then it would SEEM like str2num() and str2double() are interchangable, drop in replacements. However, if the string is not a number, they behave differently ... Returning an NaN makes sense, because ‘x’ is not a number.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 790294-str2num-returning-value-while-the-preferred-str2double-returning-nan
str2num returning value while the preferred str2double returning NaN... - MATLAB Answers - MATLAB Central
April 1, 2021 - New to MATLAB, so maybe this is a stupid question. I have the following script in MATLAB to run a python script and return a value (3.4763, for eg). When I use str2num like below, I get a the value in p. However, MATLAB suggests to use str2double. When I do that, I get NaN instead of the value.