PSON
PSON

Reputation: 11

undefined variable in MATLAB

I am newbie to MATLAB .I have written a code to upsample a data.when executed always shrows the particular error(below)

??? Input argument "n" is undefined. Error in ==> upsamp at 7 mm=min(n)

but when i just write the foll. output [n1,y]=upsamp([1,2,3,4,5,6],-1:4,3) command window ,its shows me the correct upsampled data with its figure.

then why the error is popping up? Or i just click on run button,and error is shown in command window.

Please help me out to debug that error:

My code is

function[n1,y]=upsamp(n,x,I)

mm=min(n)
mx=max(n)
n1=mm*I:(mx*I+I-1)
x1=x'
x1=[x1,zeros(length(x),I-1)]
x1=x1'
y=(x1(:))'

subplot(2,1,1)
stem(n,x)
title('original sequence ')
xlabel('Range')
ylabel('sequence')

subplot(2,1,2)
stem(n1,y)
title(' unsampling')
xlabel('Range')
ylabel('sequence')

end

Upvotes: 0

Views: 1147

Answers (3)

Amro
Amro

Reputation: 124543

As others have noted, if you want to run a function that takes input arguments, you have to call it manually from the command prompt with any required arguments.

Otherwise, if you like to use the Run button (F5) from the editor, consider creating a run configuration (they can be used in smart ways)

run_configuration

Upvotes: 3

Ben Voigt
Ben Voigt

Reputation: 283624

The run button calls your function with no arguments.

Since arguments to your function are non-optional, you get an error.

Either call your function from the interactive Command Window, or write a short script that provides appropriate arguments, and use the Run button with that script. You can still single-step into your function.

Upvotes: 0

John Colby
John Colby

Reputation: 22588

The "run" button is only for scripts (i.e. just a plain list of statements without "function" at the top). This is a function, so it should only get called from the matlab command line like you described.

Upvotes: 1

Related Questions