Plot a function from another .m file in MATLab 2019 - Please help!!!
8 ビュー (過去 30 日間)
古いコメントを表示
I have this function:
% This function file to be used in conjunction with m5.m
% of Project 5 on permanent magnet drive in Chapter 10.
function y = M5TORQV(sind,Temo,Em,Va,xd,xq)
y = Temo + (Em*Va/xd)*sind + Va*Va*(1/xq - 1/xd)*sind*sqrt(1-sind*sind);
and I call it in another file .m:
clf;
% plots of Figure No.1
subplot(4,1,1)
plot(y(:,1),y(:,2),'-')
ylabel('Tem* in pu')
axis([-inf inf -1.5 1.5])
title('Torque command')
subplot(4,1,2)
plot(y(:,1),y(:,7),'-')
ylabel('Tem in pu')
axis([-inf inf -1.5 1.5])
title('Output torque')
subplot(4,1,3)
plot(y(:,1),y(:,3),'-')
ylabel('Iq* in pu')
axis([-inf inf -1.5 1.5])
title('Rotor reference Iq command')
subplot(4,1,4)
plot(y(:,1),y(:,4),'-')
title('Rotor reference Id command')
ylabel('Id* in pu')
axis([-inf inf -1.5 1.5])
xlabel('Time in sec')
but for some reason, I get this error:
Undefined function or variable 'y'.
Error in m5 (line 281)
plot(y(:,1),y(:,2),'-')
Can you help me, please?
3 件のコメント
採用された回答
Steven Lord
2021 年 5 月 30 日
I have this function:
[snip the text of the function]
and I call it in another file .m:
No, you don't call it in that file, at least based on the excerpt of the code from that file that you posted.
Just because the M5TORQV function happens to contain a variable named y and return it as output does not automatically make references to y in later code call that function and refer to that output argument. Many functions in MATLAB contain as part of their inner workings a variable named y, and some of those return that variable as an output argument.
If you want to call M5TORQV you need to explicitly call it in your other file. Or you need to include some other code that creates the variable y before you try to use it.
その他の回答 (1 件)
IONETE Cosmin
2022 年 6 月 15 日
Hi Teea,
Steven's answer is OK.
In defining the function, the output variable 'y' is a formal parameter. The function will need to be called in your MATLAB program as
>> y = M5TORQV (1,1,1,1,1,1);
and then everything should work out.
I don't know the input parameters, I used the value '1' for all parameters as an example, but I'm afraid that the input parameters have vector values since the variable y used for plotting is of matrix type. However, the initial error message should disappear!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Two y-axis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!