testcell.m

来自「这是机械工业张德丰《MATLAB与外部程序接口编程》随书源码」· M 代码 · 共 32 行

M
32
字号
%保存为testcell.m文件
function[]=testcell()
%function[]=testcell()
tcell=cell(2,3)
tcell{1,1}=[1 2 3;4 5 6;7 8 9;];
%...表示续行符号
tcell{1,2}=struct('name','李月',...
    'college','北京科技大学',...
    'phone','01063320501',...
    'specialties',{'平面设计','网站制作'});
tcell{1,3}=[2+3*i 5+6*i;3+3*i 0.1+0.558*i;];
tempcell=cell(2,2);
tempcell{1,1}='string';
tempcell{1,2}=[2 4;6 8;];
tempcell{2,1}=[7 8 9];
tempcell{2,2}=32+i;
tcell{2,1}=tempcell;
tcell{2,2}='Hello World!';
tcell{2,3}=[9 8 6;5 4 3;2 1 7];
%采用"{"和"}"索引得到相应元组阵列元素
for i=1:2
    for j=1:3
        disp(tcell{i,j})
    end
end
%通过"("和")"索引得到1*1的相应元组阵列
for i=1:2
    for j=1:3
        disp(tcell(i,j))
    end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?