Error when calling a previously made function in a separate script. Any ideas?

2 ビュー (過去 30 日間)
Reece Nasse
Reece Nasse 2018 年 4 月 25 日
コメント済み: Ameer Hamza 2018 年 4 月 25 日
I keep getting an Error when calling a previously made function that was made in a separate script, even when it is on my path. This piece of code performs a multiple regression iterative search task with 3 parameters.
Here is the original function that gets called later(Both original function script and the other Script it is being called in are attached) I created the function that is being called myself.
Open each attachment separately and run iterative search script to see error.
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 25 日
The function needs White blood cell count as well as red blood cell count. It ignores all other table properties.
Reece Nasse
Reece Nasse 2018 年 4 月 25 日
So how should it look then? Are you referring to this line of code being changed or the original function? It may seem like a stupid question but I am new to using matlab and this is only the second piece of code ive ever written. Thanks.

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 4 月 25 日
The problem is caused by this line
WR = table(RedBloodCellCount,MeanWBCM30,'variablenames',{'RedBloodCellCount','MeanWBCM30'});% 2 previosly defined varibles are put into a table.
The function MultipleRegression require tables with field WhiteBloodCellCount and RedBloodCellCount, which the table WR does not contain. Change the 2nd variable name to WhiteBloodCellCount and it will give no syntax error.
WR = table(RedBloodCellCount,MeanWBCM30,'variablenames',{'RedBloodCellCount','WhiteBloodCellCount'});% 2 previosly defined varibles are put into a table.
*** "the following passage is just a suggestion based on observing your code, you may ignore it if you are sure about what you are doing."
It appears that you are making a logical mistake in your code. The new table WR contain the same value for WhiteBloodCellCount, so it might not be a good way to evaluate the performance of [Bestparams1, Bestparams2, Bestparams3]. It might be better to compare the parameters based on the original Data table as follow
Curve = MultipleRegression([Bestparams1,Bestparams2,Bestparams3], Data);
Also as I mentioned in Answer to your previous question, the line
SSD = A(:,3)-SimulatedY.^2; %calculate squared deviations at each data point in column 3 of data table (the row labelled IQ). Column 3 represents Y values.
is definitely wrong which is also indicated by your comment after the line. The correct is
SSD = (A(:,3)-SimulatedY).^2;
Hope this will help.
  2 件のコメント
Reece Nasse
Reece Nasse 2018 年 4 月 25 日
Thank you very much, I changed the line relating to SSD and the name of the table, my script ran fine and produced my graph when I called the function.
Ameer Hamza
Ameer Hamza 2018 年 4 月 25 日
You are welcome.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by