MATLAB基本数据类型

    xiaoxiao2021-12-14  57

    close all; clear all; clc; %% 整型数据的一些操作 a=round(3.4);%四舍五入取值 b=fix(-1.9);%舍去小数部分 c=floor(3.4);%小于该数且离其最近的数 d=ceil(-1.9);%大于该数且离其最近的数 e=123; f=single(e);%转换为单精度 %% 字符串的一些操作 s1='muahdahd'; s2='sahfglahdfl'; s3=strcat(s1,s2);%字符串横向连接 s4=strvcat(s1,s2);%字符串纵向连接 s5=upper(s1);%所有字母转换为大写 s6=s1(4:7);%取某一个区间的字符串 [m,n]=size(s1);%返回字符串大小 %% 逻辑运算符 A=eye(3);%生成对角阵 B=true(4);%生成逻辑真矩阵 %% 函数句柄,可以使用一些私有化函数 fhandle=@sin; y1=fhandle(2*pi); y2=functions(fhandle); %% 元胞数组 stu=cell(2);%2*2的细胞数组 stu{1,1}={'fjahf','ahdkah','hsdahl'}; stu{1,2}={'12631','424'}; stu{2,1}={'f','m'}; stu{2,2}={20,19}; stu{1,1}(1);%获取第一个元胞的第一个元素 stu1=cellfun('length',stu);%对每一个元胞都执行指定函数 cellplot(stu); %% 结构 student=struct('name',{'a','b'},'age',{11,22},'score',{rand(3)*10,rand(3)*10});%创建一个1×2的结构体,数据的维数需要相同 student(2).name; student(2).score(1,:);%访问数组第二个元素的score字段的第一行数据
    转载请注明原文地址: https://ju.6miu.com/read-969530.html

    最新回复(0)