matlab练习记录笔记

1.设A为3行4列的矩阵,B为一个行数大于3的矩阵,写出命令

(1)删除A的第1、3列

             A=rand(3,4)

                 法一: A1=A([1,2,3],[2])
                法二:A(:,[1,3])=[]#删除第1,3列)

(2)删除B的倒数第三行
           B=rand(4,4)
                 法一:B1=B([1,3,4],[1,2,3,4])
                 法二:B([2],:)=[]

2.把matlab建立一个字符串数组"i'm A STUDENT'",完成以下命令要求。
(1)把大写字母改成小写

                 A="i'm A STUDENT'"
                lower(A)
(2)把小写字母改成大写
(3)首字母变成大写

               B=[upper(A(1)A(2:end)]
              对于好几个单词的情况,例如
                             A='model including effects of precombustioin'
                            b=[0 find(A==' ')]
                            A(b+1)=upper(A(b+1)       
(4)大小写互换

                            lidx = s>='a' & s<='z'; 
                            uidx = s>='A' & s<='Z'; 
                            s(lidx) = upper(s(lidx)); 
                            s(uidx) = lower(s(uidx)); 
                            s
(5)将字符串中student改成teacher

法一:a='i am a student'
           disp(a)
           temp='student'
           new_temp='teacher'
           loc=strfind(a,temp)
           a(loc(1):loc(1)+1)=new_temp

     法二:
           s1=a
           strrep(s1,'student','teacher')

(6)将字符串I am a student!赋给一个字符数组,然后输出该串中的student!。请用指针完 

                      // 初始化字符串str
                                  char str[] = "I am a student!";
                     // 使用指针
                                 char *p = str + 7;
                     // 输出"student!"
                                  printf( "%s", p ); 
(7)逆序,改成 student a am i
 

猜你喜欢

转载自blog.csdn.net/Mo18312723429/article/details/83045410