zoukankan      html  css  js  c++  java
  • MATLAB常用字符串函数之二

    1,lower和upper

    lower:
    将包含的全部字母转换为小写。
    upper:
    将包含的全部字母转化为大写。

    实例一:
    >>str='Sophia is a good girl.';
    >>Big=upper(str)
    Big =
    SOPHIA IS A GOOD GIRL.
    实例二:
    >>Small=lower(str)
    Small =
    sophia is a good girl.

    2,sort和sortrows

    sort:
    按值的大小对数组元素排序。
    sortrows:
    按列值得升序或降序,对矩阵的每行排序。

    实例一:
    >>a=[1 4 89;4 9 2;3 8 2];
    >>Res=sort(a)
    Res =
    1 4 2
    3 8 2
    4 9 89
    实例二:
    >>ResRow=sortrows(a)
    ResRow =
    1 4 89
    3 8 2
    4 9 2
    >>ResRow=sortrows(a,2)
    ResRow =
    1 4 89
    3 8 2
    4 9 2
    >>ResRow=sortrows(a,3)
    ResRow =
    4 9 2
    3 8 2
    1 4 89

    3,strtrim

    移除字符串首部和尾部的空白。

    实例一:
    >>str=' Sophia is a good girl. ';
    >>Res=strtrim(str)
    Res =
    Sophia is a good girl.
    >>length(str)
    ans =
    26
    >>length(Res)
    ans =
    22

    4,strrep

    用第三个参数字符串替换第一个字符串中第二个字符串。

    实例一:
    >>claim='This is a good example.';
    >>new_claim=strrep(claim,'good','great')
    new_claim =
    This is a great example.

    5,strjust

    调整字符数组的对其方式,其他位置填充空格。
    实例一:

    >>str=' sophia is a good girl. ';%前后各一个空格
    >>Res=strjust(str,'left')
    Res =
    sophia is a good girl. %后面两个空格,前面没有空格。
    >>Res=strjust(str,'center')
    Res =
    sophia is a good girl. %前后各一个空格
    >>Res=strjust(str,'right')
    Res =
    sophia is a good girl.%前面两个空格,后面没有空格。

    6,findstr和strfind

    findstr:
    在长字符串中搜索短字符串。
    strfind:
    在第一个参数字符串中搜索第二个参数字符串。

    实例一:
    >>str1='sophia is a good girl';
    >>str2='sophia';
    >>Res1=findstr(str1,str2)
    Res1 =
    1
    >>Res2=findstr(str2,str1)
    Res2 =
    1
    实例二:
    >>Res2=strfind(str2,str1)
    Res2 =
    []
    >>Res2=strfind(str1,str2)
    Res2 =
    1

  • 相关阅读:
    tty & pty & pts
    PageRank
    How to run a terminal inside of vim?
    vimdiff
    svn's tree conflict
    svn's diff command
    符号表分离
    gcc -D
    Options for Debugging Your Program or GCC
    invoking gdb
  • 原文地址:https://www.cnblogs.com/sophia-hxw/p/6224307.html
Copyright © 2011-2022 走看看