필터 지우기
필터 지우기

why any function as m file, does not work on my pc?

조회 수: 1 (최근 30일)
saeede soleymani
saeede soleymani 2015년 11월 25일
댓글: saeede soleymani 2015년 11월 26일
I have MATLAB2014a 32bit on my pc with windows8 64bit. I wrote an m file (function), but it didn't work and had error. after, I write a so easy m file, and has error!!!!! what should I do?
function y=new_state(x,v)
y=x+v
end
error is
Error using new_state (line 2)
Not enough input arguments.

채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 25일
If you run Simulink from the GUI menu, then variables for To Workspace blocks go in to the base workspace.
If you run Simulink by using the sim() command, then variables for To Workspace blocks go in to the workspace of the function that you call sim() in.
If you need to pull a variable out of the base workspace you can do that using evalin()
a = evalin('base', 'a');
b = evalin('base', 'b');
new_state(a, b);
  댓글 수: 1
saeede soleymani
saeede soleymani 2015년 11월 26일
Dear Mr Roberson, thanks so much for your replying. as yet, all of my questions in mathworks site answered by you. thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ilham Hardy
Ilham Hardy 2015년 11월 25일
And did you call that with two arguments?
new_state(2,3)
  댓글 수: 2
saeede soleymani
saeede soleymani 2015년 11월 25일
thanks a lot, yes,it works with this. but I want call it from the main function with variables that defined in workspace from simulink
Ilham Hardy
Ilham Hardy 2015년 11월 25일
Say you have variable a and b in the base workspace, then you can call
y = new_state(a,b);
If you want to call the new_state from within the function, you do not have direct access to the base workspace.
Perhaps it will best for you to open new question thread and better formulate your question (with more examples)?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by