I am having some issues calling a function in a script file.

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commenti
Byronb
Byronb il 29 Apr 2016
One more question if you or anyone is still looking at this. In the original function the n number of outputs are arranged so that the index of the first is assigned to 1 on the plot created with my script. However since i'm dealing with populations I need this 'initial' value to be assigned to 0 on the plot. Or in other words, for every y value I have, the x value needs to decrease by 1. So my graph will be translated left 1 unit.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by