problem with 'extract' function

I am trying to extract characters from a string at a specific position using the 'extract' function.
However, even when entering the example code into my matlab program I get the error
Undefined function 'extract' for input arguments of type 'string'.
Can somebody help with this?
Matlab help page:
Section: Extract Character at Numeric Position
Create a string.
str = "All's well that ends well"
Extract the first character in the string.
extract(str,1)
From the command window:
>> str = "All's well that ends well"
str =
"All's well that ends well"
>> extract(str,1)
Undefined function 'extract' for input arguments of type 'string'.
Thanks!

回答 (2 件)

Star Strider
Star Strider 2021 年 1 月 30 日

1 投票

The extract function was introduced in R2020b. If you have an earlier version/release, you need to upgrade to be able to use it. If you have R2020b and are still unable to use extract, run these commands:
restoredefaultpath
rehash toolboxcache
from a script or your Command Window and then try running it again. If you are still having problems after that, Contact Support.

2 件のコメント

Damian Maxwell
Damian Maxwell 2021 年 2 月 3 日
Thank you so much!
Damian Maxwell
Damian Maxwell 2021 年 2 月 3 日
I'll try to upgrade from my 2019 version

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

dpb
dpb 2021 年 1 月 30 日

1 投票

What do you get when you type
ver
at command line?
extract wasn't introduced until just now in R2020b so if you have a release earlier than that, you'll either have to upgrade or use the {} notation to get to the underlying char() string inside the string class string...
>> str = "All's well that ends well"
Extract the first character in the string.
extract(str,1)
str =
"All's well that ends well"
Unrecognized function or variable 'Extract'.
>> str{:}(1)
ans =
'A'
>>

2 件のコメント

Damian Maxwell
Damian Maxwell 2021 年 2 月 3 日
Thanks DB. Your alternative method works.
dpb
dpb 2021 年 2 月 3 日
That was the only way to extract a substring from a string variable prior to R2020b that released extract into the wild.

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

カテゴリ

質問済み:

2021 年 1 月 30 日

コメント済み:

dpb
2021 年 2 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by