自定义一个函数,将字符串按空格分隔。
function arr = splitBySpace(str) index = 1; temp = []; len = length(str); for i=1:len if str(i)==' ' if str(i)==len temp = [temp, str(i)]; end arr{index} = temp; index = index + 1; temp = []; else temp = [temp, str(i)]; end end
2 num2cell 用法
参考:http://www.matlabsky.com/thread-3396-1-1.html
刚刚回复了一下,结果出错了,又来一次
这是一个把数值数组转换为元胞数组的一个指令
格式是:b=num2cell(a,dim)
有下面几种情况:
1.dim缺省或dim=3,则是把数值数组转换成为维数大小相同的元胞数组
- >> a=rand(4)
- a =
- 0.9572 0.4218 0.6557 0.6787
- 0.4854 0.9157 0.0357 0.7577
- 0.8003 0.7922 0.8491 0.7431
- 0.1419 0.9595 0.9340 0.3922
- >> b=num2cell(a)
- b =
- [0.9572] [0.4218] [0.6557] [0.6787]
- [0.4854] [0.9157] [0.0357] [0.7577]
- [0.8003] [0.7922] [0.8491] [0.7431]
- [0.1419] [0.9595] [0.9340] [0.3922]
2.dim=1,表示把“行”方向元素装入元胞数组的一个元胞(n*1的列向量)
- >> c=num2cell(a,1)
- c =
- [4x1 double] [4x1 double] [4x1 double] [4x1 double]
<ignore_js_op>
3.dim=2,表示把“列”方向元素装入元包数组的一个元胞(1*n的行向量)
- >> d=num2cell(a,2)
- d =
- [1x4 double]
- [1x4 double]
- [1x4 double]
- [1x4 double]
<ignore_js_op>
4.dim=[1 2]或[2 1],这个我在书上没看到过,我自己的理解是:把“行和列”方向的元素装入元胞数组的一个元胞(n*n的矩阵)
- >> e=num2cell(a,[1 2])
- e =
- [4x4 double]
<ignore_js_op>
双击matlab中上面那个图标所在地方出现下面内容:
<ignore_js_op>
如果你的矩阵就是这么一个形式,别的形式语句就没别的意思了。如果你造一个带页的数值数组,就还有别的语句,那个麻烦得很
楼上基本解释了二维矩阵的情况,对多维矩阵,可以类推,dim就是维,[dim1 dim2 dim3]就是将第dim1 dim2和第dim3合并作为一个元胞,如果dim3大于了矩阵的维数,等同于[dim1 dim2]
3 绘图
1)指定figure的标题样式等
fg1=figure('numbertitle','off','name','标题名称,'color','white');
saveas(fg1,'保存图形的名称');
你好,请问能不能在生figure的时候就更该figure的标题呢??谢谢
在其他地方找到的 我运行成功,希望对你有用
set(figure(1),'NumberTitle','off','Name','1') ; %n1为你要的名称(http://www.ilovematlab.cn/thread-134155-1-1.html)
4 界面编程
[file,path] = uigetfile('*.txt','Read Sensor File(*.txt)'); % Get file directory
filename = [path file];