how create correct function

조회 수: 2 (최근 30일)
fatema saba
fatema saba 2014년 11월 28일
댓글: fatema saba 2014년 11월 28일
Hi I wrote something like that and I think it is a function but I got some errors when I run it. What is mistake?
function t = Aineq(k1,q,e,a,b)
m=input('input m=')
n=input('input n=')
q=sparse(m*n,m*n)
e=speye(m*n)
k1=-4*e
a=constraint12b(m,n)
b=constraint12c(m,n)
t=[k1 q e q;q k1 q e;a q e q;q a q e;b q -e q;q b q -e]
end
I point that constraint12b and constraint12c are functions separately and could be ran correctly.
  댓글 수: 4
Guillaume
Guillaume 2014년 11월 28일
The code that you posted in your question does not match the error message that you've just posted. Line 2 in your question is:
m=input('input m=')
whereas according to the error, it is:
q=sparse(m*n,m*n)
Obviously, if you remove the line that creates m, then it's not going to be defined.
In the future, please post the exact code you use, otherwise you're sending us on a wild goose chase.
Anyway, Azzi's answer should be what you're looking for.
fatema saba
fatema saba 2014년 11월 28일
Thank you for your attention but I send the image of my function to you again. I exactly received the error that I sent you before
my error:
>> t = Aineq(k1,q,e,a,b) ??? Undefined function or variable 'm'.
Error in ==> aineq at 2
q=sparse(m*n,m*n)

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 28일
Your function should be something like this
function t = Aineq(m,n)
q=sparse(m*n,m*n)
e=speye(m*n)
k1=-4*e
a=constraint12b(m,n)
b=constraint12c(m,n)
t=[k1 q e q;q k1 q e;a q e q;q a q e;b q -e q;q b q -e]
save this as Aineq.m, then if you want to run your function, you have to use another script or from Matlab windows command
n=10
m=20
t = Aineq(m,n)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by