作者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://www.ptt.cc/bbs/MATLAB/M.1439103351.A.A96.html
※ 編輯: a339708 (111.255.106.245), 08/09/2015 14:57:40
推 profyang: u1是個變數 u2, u3也分別是另一個變數 但你這函數似乎 08/09 14:57
→ profyang: 沒用到它們 只用到u這個變數 08/09 14:58
所以要新增一行u的變數囉? 因為在run時 他顯示aaa(u) 我把它改成aaa(1) 也是會出現
錯誤。
※ 編輯: a339708 (111.255.106.245), 08/09/2015 15:02:51
推 profyang: 他comment我是看不太懂啥意思啦 但反正這function的inpu 08/09 15:04
→ profyang: 就只有u而已 你要了解這個u的意思 然後給他input 在 08/09 15:05
→ profyang: command window就用sf=aaa(u) 這樣去call他 他就會給你 08/09 15:05
→ profyang: sf這樣 08/09 15:05
恩恩 那u一定是一個數值嗎? 還是它可能是文字或檔案名稱?
※ 編輯: a339708 (111.255.106.245), 08/09/2015 15:16:41
→ celestialgod: u是向量吧 08/09 15:20
推 profyang: 看他function裡面的code, u應該就是個1*3或3*1的向量 08/09 15:20
→ profyang: 當然你中間有省略啥我不知道 有可能是更大的向量 08/09 15:21
這個是Paper的網址
http://goo.gl/F30wGn 麻煩幫我看一下><"
※ 編輯: a339708 (111.255.106.245), 08/09/2015 15:36:44
→ celestialgod: 看起來就是3X1的向量 08/09 15:53