I am having some issues calling a function in a script file.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Byronb
am 29 Apr. 2016
Kommentiert: Walter Roberson
am 29 Apr. 2016
At the moment I have a previously saved function, it as 7 inputs and 2 output. The 2 outputs are the inputs that I need to create 2 subplots with the output as my y, and the x being the index of these values. For example my function;
function[II,JJ]=RLC(R,L,C,tinc,n,ii,jj)
I need to call this RLC function in the first line of my script, but I can only call it. I can't redefine it, so no more code in regards to the RLC are to be present in the script. This is my script so far;
RLC(2,0.01,0.01,0.01,10,1,0);
subplot(1,2,1),plot(II)
axis([0,9,-25,15])
title({'\bf Plot of current in RCL series circuit';});
xlabel('Time stamp number n');
ylabel('Current in Amperes');
grid off
subplot(1,2,2),plot(JJ)
axis([0,9,-25,15])
title({'\bf Plot of current in RCL series circuit';});
xlabel('Time stamp number n');
ylabel('Numerical differential of current in Ampere/sec');
grid off
Even though this prints outputs II and JJ from the function to the command window, I can't use it in my plot. I have tried fplot as well but no luck.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Apr. 2016
The names you list on the left side of a "function" statement are the "dummy" names for the outputs -- local names used to refer to the positional outputs, just the same way that inside your function R is the dummy name used to refer to whatever is passed in the first parameter.
In a function when you assign to a name that appears on output, at the end of the function, the final value will be assigned to whatever actual location you designated when you called the function, not to variables with the dummy names. Assigning to II or JJ inside the function does not trigger assigning to variables named II or JJ outside the function -- unless, that is, you happened to name those at the outputs.
Anyhow, call
[II, JJ] = RLC(2,0.01,0.01,0.01,10,1,0);
Here you do happen to name II and JJ as the variables to receive the values. But you could have had
[Iv, Lv] = RLC(2,0.01,0.01,0.01,10,1,0);
plot(Iv)
because then it would be Iv that was assigned to.
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!