Question

function simps()
A=[0,0];
B=[0,0]; 
set_param('circuit/LINE2','Capacitance',num2str(C(1)))
        sim('circuit')
    B=[Real,Reactive];
        A=[A;B];    
end

C is a matrix. It contains 10 variables. Like 1,10,50,100 random.It is in uF. circuit is name of file Real Reactive are the to workspace name. LINE2 is the name of the RLC branch. RLC branch contains only capacitance.

I am getting error

"Undefined function or method 'C' for input arguments of type 'double'. "

I have searched stackoverflow, everybody talks about directory problem. But all my files are inside RUN directory.

I did

>> which C

It returned

C is a variable.

So I think the C is in directory path of matlab. So where is the error?

Was it helpful?

Solution

You've to do either of following

a) pass C as argument to function simps()

OR

b) evaluate C from workspace

C = evalin( 'base', 'C' );

inside the function before its use.

Also, use of eval and evalin is generally discouraged as it makes your code harder to follow and re-use.

Tip :

You may want to combine both like following

function simps(C)
if nargin == 0
    C= evalin( 'base', 'C' );
end
% Your code
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top