Looking for alternative of extractBetween function

close all
clear all
clc
name = 'Covid_strains';
file = strcat(name,'.fasta');
sequences = fastaread(file);
The code extract the sequences from the fasta file "Covid_strains". The file contains multiple sequences. The fastaread function create a structure containing Header and Sequences. Now I want to extract the some part of the header and store it in a table. The table will be the response variable for the predictor. I wanted to use extractbetween function for this. But since I am using older version of MATLAB, the function is not available to me. Please help.

2 件のコメント

Rik
Rik 2021 年 11 月 4 日
You didn't enter your release when you posted your question, which makes it harder to help you.
I suspect the best choice would be to use regexp. With a regular expression you can capture the tokens.
SUBHAJIT KAR
SUBHAJIT KAR 2021 年 11 月 4 日
I am using version 2016a. How can I extract 'B.1.2' from the the expression 'OK584715.1 |B.1.2' , using regexp ?

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

 採用された回答

Rik
Rik 2021 年 11 月 4 日

1 投票

You need to come up with a regular expression that will exactly match what you want to extract. Below is my guess for what you want.
RE=['\|',... match a literal |
'(.*)',... capture any character in a token
'($|\n)'];% end of matched substring should be a newline or the end of the string
txt='OK584715.1 |B.1.2';
x=regexp(txt,RE,'tokens');x{1}
ans = 1×2 cell array
{'B.1.2'} {0×0 char}

4 件のコメント

SUBHAJIT KAR
SUBHAJIT KAR 2021 年 11 月 7 日
Thanks a lot. But the command creating cell arrays under a cell array.
close all
clear all
clc
name = 'Covid_strains'
file = strcat(name,'.fasta')
seqs = fastaread(file)
T = {seqs.Header}'
T1 = cell2table(T,'VariableNames',{'Label'})
RE = ['\|','(.*)','($|\n)'];
x =regexp(T1.Label,RE,'tokens')
How can I get the output as a string insted of cell array?
Steven Lord
Steven Lord 2021 年 11 月 7 日
How can I get the output as a string insted[sic] of cell array?
With release R2016a? You don't.
According to the documentation page the string function was introduced in release R2016b.
Rik
Rik 2021 年 11 月 7 日
Why did you remove all the semicolons as well as all documentation for the regular expression? And why are you closing all figures?
SUBHAJIT KAR
SUBHAJIT KAR 2021 年 11 月 9 日
I actually forget to add those semicolons.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

リリース

R2016a

質問済み:

2021 年 11 月 4 日

コメント済み:

2021 年 11 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by