ERROR when attempting to use imported data in a function

I have set up a price function that is supposed to use market prices (vector 'PriceM') that I imported. When running the code MATLAB tells me that the variable is unknown. I then figured I have to load the variable into the workspace before the variable is used by my code. That gave me the error: Attempt to add "PriceM" to a static workspace. How can I access the imported data in my function? Thanks!
function y = Price1(a,b,c,d,P)
a = 100;
b = 0.05;
c = 0.3;
d = 1.5;
P = PriceM;

 採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 18 日

0 投票

Remove those lines
a = 100;
b = 0.05;
c = 0.3;
d = 1.5;
P = PriceM;
from your code and save the file.
Now, go down to the command line and command
a = 100;
b = 0.05;
c = 0.3;
d = 1.5;
P = PriceM;
y = Price1(a, b, c, d, P);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by