Access matrix values inside of a function

조회 수: 9(최근 30일)
Christian S.
Christian S. 2021년 3월 2일
댓글: Christian S. 2021년 3월 4일
Hi MATLAB-Folks,
I'm asking with a beginner problem for your help, I searched the forum for an answer but without sucess:
I have a script, that creates a vector, lets say as an example:
>> g_x_contact=[0 0 1 2 3 4 0 0]
afterwards I'm creating a function, that uses the corresponding value of the vector within.
For example:
function Integral = pressure_integral(x)
Integral = g_x_contact(x).*(x/2)
So I want the function to use the value at position x and calculate the according steps afterwards.
Here the promt-line >> pressure_integral(6) should calculated with the sixth element: 4.*(6/2)=12
Instead I get the error-Message
Unrecognized function or variable 'g_x_contact'.
Error in pressure_integral (line 6)
Integral = g_x_contact(x).*(x/2)
Can anybody give me a hint, how the access the Vector?
Thank you in advance and very best

채택된 답변

Bob Thompson
Bob Thompson 2021년 3월 2일
편집: Bob Thompson 2021년 3월 2일
I believe this is the purpose of global variables, but I could be wrong. I don't really use them much.
  댓글 수: 5
Christian S.
Christian S. 2021년 3월 4일
Thank you guys very much!

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

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by