undefined variable in MATLAB

让人想犯罪 __ 提交于 2021-02-04 21:33:54

问题


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

回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/7856860/undefined-variable-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!