Plot a function from another .m file in MATLab 2019 - Please help!!!

8 ビュー (過去 30 日間)
Teea Eliade
Teea Eliade 2021 年 5 月 30 日
回答済み: IONETE Cosmin 2022 年 6 月 15 日
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 件のコメント
Teea Eliade
Teea Eliade 2021 年 5 月 30 日
subplot(4,1,1)
plot(y(:,1),y(:,2),'-')
Teea Eliade
Teea Eliade 2021 年 5 月 30 日
編集済み: Teea Eliade 2021 年 5 月 30 日
the code is not mine, is of professor Chee Mun Ong- I just try to execute it in MATLab 2019 but it is not working
the specific files are m5.m and m5torqv.m

サインインしてコメントする。

採用された回答

Steven Lord
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 件のコメント
Teea Eliade
Teea Eliade 2021 年 5 月 30 日
Ok, but I still don't understand why this code is not compiling, as it is. I tried to fix it and I thought that there was the problem. If it is not this, I don't know what it is.

サインインしてコメントする。

その他の回答 (1 件)

IONETE Cosmin
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!

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by