作者a339708 (Sai)
看板MATLAB
标题[讨论] 练习matlab function时遇到一些编辑问题
时间Sun Aug 9 14:55:48 2015
各位前辈好,本人刚接触matlab一个月,有很多问题不懂请多多包涵
切入正题,我在制作matlab funciton的时候遇到了一些问题
------------------------------------------------------------
问题1:在Paper里附的Code的第一行有注明一段:
% Inputs are magnitude u1(:),angle u2(:), and
% ramp time signal for comparison u3(:)
请问这是要自行要打在程式码里面吗?
问题2:在打完Code以後要run程式码时都会叫我输入aaa(u)里面的u才能执行
我随便输入一个数值例如1,就会出现以下错误代码:
aaa(1)
Attempted to access u(2); index out of bounds because numel(u)=1.
Error in aaa (line 3)
x=u(2); y=u(3);
本人用了好几天都用不好,希望各位可以个忙,感恩~~~
------------------------Code----------------------------
% Inputs are magnitude u1(:),angle u2(:), and
% ramp time signal for comparison u3(:)
function [sf]=aaa(u)
ts=0.0002;vdc=1;peak_phase_max= vdc/sqrt(3);
x=u(2); y=u(3);
mag=(u(1)/peak_phase_max) * ts;
.
.
.
.
.
.
.
end
end
sa=v1(j);
sb=v2(j);
sc=v3(j);
end
sf=[sa, sb, sc];
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.255.106.245
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1439103351.A.A96.html
※ 编辑: a339708 (111.255.106.245), 08/09/2015 14:57:40
1F:推 profyang: u1是个变数 u2, u3也分别是另一个变数 但你这函数似乎 08/09 14:57
2F:→ profyang: 没用到它们 只用到u这个变数 08/09 14:58
所以要新增一行u的变数罗? 因为在run时 他显示aaa(u) 我把它改成aaa(1) 也是会出现
错误。
※ 编辑: a339708 (111.255.106.245), 08/09/2015 15:02:51
3F:推 profyang: 他comment我是看不太懂啥意思啦 但反正这function的inpu 08/09 15:04
4F:→ profyang: 就只有u而已 你要了解这个u的意思 然後给他input 在 08/09 15:05
5F:→ profyang: command window就用sf=aaa(u) 这样去call他 他就会给你 08/09 15:05
6F:→ profyang: sf这样 08/09 15:05
恩恩 那u一定是一个数值吗? 还是它可能是文字或档案名称?
※ 编辑: a339708 (111.255.106.245), 08/09/2015 15:16:41
7F:→ celestialgod: u是向量吧 08/09 15:20
8F:推 profyang: 看他function里面的code, u应该就是个1*3或3*1的向量 08/09 15:20
9F:→ profyang: 当然你中间有省略啥我不知道 有可能是更大的向量 08/09 15:21
这个是Paper的网址
http://goo.gl/F30wGn 麻烦帮我看一下><"
※ 编辑: a339708 (111.255.106.245), 08/09/2015 15:36:44
10F:→ celestialgod: 看起来就是3X1的向量 08/09 15:53