Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何使用matlab读取字符串中的数字_String_Matlab - Fatal编程技术网

String 如何使用matlab读取字符串中的数字

String 如何使用matlab读取字符串中的数字,string,matlab,String,Matlab,我有一个非标准格式的文件,我想读取它的特定部分,包括实数或整数 str1='N.ELBETI.150.L10'; str2='KARDIA_3.150.L20'; str3='axeloos1.15.75.L20'; str4='florina2.6.3.L2.1'; 我只想将数字存储在每个字符串的中间部分和末尾,即: 来自str1的150和10,来自str2的150和20,来自str3的15.75和20,来自str4的6.3和2.1 我试过好几种方法,但我做不到。你能帮我吗?像这样使用

我有一个非标准格式的文件,我想读取它的特定部分,包括实数或整数

str1='N.ELBETI.150.L10';

str2='KARDIA_3.150.L20';

str3='axeloos1.15.75.L20';

str4='florina2.6.3.L2.1';
我只想将数字存储在每个字符串的中间部分和末尾,即:

来自str1的150和10,来自str2的150和20,来自str3的15.75和20,来自str4的6.3和2.1
我试过好几种方法,但我做不到。你能帮我吗?

像这样使用
regexp

要获取第一个数字:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)
要获取最后一个号码,请执行以下操作:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)

这些命令也适用于其他字符串

使用
regexp
,如下所示:

要获取第一个数字:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)
要获取最后一个号码,请执行以下操作:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)

这些命令也适用于其他字符串

使用
regexp
,如下所示:

要获取第一个数字:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)
要获取最后一个号码,请执行以下操作:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)

这些命令也适用于其他字符串

使用
regexp
,如下所示:

要获取第一个数字:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)
要获取最后一个号码,请执行以下操作:

str1(regexp(str1,'\.\d')+1:regexp(str1,'L\d')-2)
str1(regexp(str1,'L\d')+1:end)

这些命令也适用于其他字符串

这是已经发布的漂亮答案的替代方案。对每个字符串应用以下函数

function [num1, num2] = extract_from_string(s)

num1 = str2num(s(find(s == '.',1,'first')+1:find(s == 'L',1,'first')-2));
num2 = str2num(s(find(s == 'L',1,'first')+1:end));

end

一个替代已经发布的好答案。对每个字符串应用以下函数

function [num1, num2] = extract_from_string(s)

num1 = str2num(s(find(s == '.',1,'first')+1:find(s == 'L',1,'first')-2));
num2 = str2num(s(find(s == 'L',1,'first')+1:end));

end

一个替代已经发布的好答案。对每个字符串应用以下函数

function [num1, num2] = extract_from_string(s)

num1 = str2num(s(find(s == '.',1,'first')+1:find(s == 'L',1,'first')-2));
num2 = str2num(s(find(s == 'L',1,'first')+1:end));

end

一个替代已经发布的好答案。对每个字符串应用以下函数

function [num1, num2] = extract_from_string(s)

num1 = str2num(s(find(s == '.',1,'first')+1:find(s == 'L',1,'first')-2));
num2 = str2num(s(find(s == 'L',1,'first')+1:end));

end


具体来说,你有没有试过哪些不起作用,以及以何种方式不起作用?对不起,regexp对str1有效,但对str4无效?具体来说,你有没有试过哪些不起作用,以及以何种方式不起作用?对不起,regexp对str1有效,但对str4无效?具体来说,你有没有试过哪些不起作用,什么方式不起作用?对不起,regexp对str1起作用,但对tr4不起作用。具体地说,你试过什么方式不起作用?对不起,regexp对str1起作用,但对tr4不起作用。在这两种情况下,我都得到了答案:空字符串:1-by-0我不知道为什么会得到空字符串。请尝试其他字符串,并记住将
str1
替换为
str2
/
str3
/
str4
(第一个命令有3个
str1
谢谢,你说得对!你能告诉我如何构建regexp以获取str1中的最后三个字符('L10')删除
+1
str1(regexp(str1,'L\d'):end)
以及如何获取str4中的第一个字符(即'florina2')?在这两种情况下,我都会得到一个答案:空字符串:1-by-0我不知道为什么会得到空字符串。请尝试其他字符串,并记住在命令的每个部分将
str1
替换为
str2
/
str3
/
str4
(第一个命令有3个
str1
谢谢,你说得对!你能告诉我如何构建regexp来获取最后三个字符('L10'在str1中)删除
+1
str1(regexp(str1,'L\d'):end)
以及如何获取第一个字符(即'florina2')在str4中?在这两种情况下,我都会得到一个答案:空字符串:1-by-0我不知道为什么会得到空字符串。请尝试其他字符串,并记住在命令的每个部分将str1替换为str2/
str3
/
str4
(第一个命令有3个
str1
谢谢,你说得对!你能告诉我如何构建regexp来获取最后三个字符('L10'在str1中)删除
+1
str1(regexp(str1,'L\d'):end)
以及如何获取第一个字符(即'florina2')在str4中?在这两种情况下,我都会得到一个答案:空字符串:1-by-0我不知道为什么会得到空字符串。请尝试其他字符串,并记住在命令的每个部分将str1替换为str2/
str3
/
str4
(第一个命令有3个
str1
谢谢,你说得对!你能告诉我如何构建regexp来获取最后三个字符('L10'在str1中)删除
+1
str1(regexp(str1,'L\d'):end)
以及如何获取str4中的第一个字符(即'florina2')?