フィルターのクリア

Can I move the contains function from Matlab 2017b to Matlab 2014b?

2 ビュー (過去 30 日間)
Charles Arentzen
Charles Arentzen 2019 年 12 月 5 日
回答済み: Charles Arentzen 2019 年 12 月 5 日
Hello,
I am facing a Matlab compatability issue regarding the contains function. I wrote a script using Matlab 2017b but want to give it to a user group who only has access to 2014b.
The main back-compatability issue is that I use the contains function to find all indices of a text-based cell vector matching a string (e.g. indices = contains(cellVec, 'string')). I then reduce a different but identically-sized cell vector using those indices (e.g. cellVec2 = cellVec2(indices)). This was working very effectively for my needs and avoids any loops. Unfortunately, I need to find a way to replace all of these contains calls - I looked into using indices = ~isempty(strfind(cellVec,'string')) but this yields a single result instead of a numeric vector of results.
Since my computer has 2014b and 2017b, is there anything I can do to poach the 2017b contains function in a way that is usable by 2014b, or can I use strfind or another function to produce a numeric vector of indices while avoiding loops?
Thanks, Charlie
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 5 日
contains is part of the string() datatype upgrades; it relies on functionality that did not exist in R2014b
Adam Danz
Adam Danz 2019 年 12 月 5 日
You could write your own function with the same name.
Maybe strcmp() or strcmpi() would suit your needs.

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

採用された回答

Charles Arentzen
Charles Arentzen 2019 年 12 月 5 日
Thanks guys, good to know. I see what you mean on the updated string datatype, so trying to port over contains is definitely not a viable path.
I was able to solve the issue by using cellfun to produce a vector output:
indices = 1-cellfun('isempty',strfind(cellVec,'string'))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by