please help

i am using the code from a former student. i run it and i gave me this error:
??? Undefined function or method 'Political' for input arguments of
type 'char'.
what does it mean? how can i change it right? the code is given as below from the former student.
X = xlsread('Political 2008.xlsx','sheet1','A1:G83');
Y = xlsread('Political 2008.xlsx','sheet1','H1:H83');
s = length (Y(1,:));
m = length (X(1,:));
for j = 1:83
f = [-Y(j,:) zeros(1,m)]';
Aeq = [zeros(1,s) X(j,:)];
beq = 1;
A = [Y -X];
b = zeros(83,1);
lb = zeros(m+s,1);
uv(:,j) = LINPROG(f,A,b,Aeq,beq,lb);
h(j) = -f'*uv(:,j);
end
please help. thank you

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 12 月 20 日

0 投票

It's a little strange because you are not using "Political" as a variable or function.
My guess is that: 1) Your Excel version is different than the origianl intended. 2) The file "Political 2008.xlsx" is not in your current folder. 3) Your MATLAB version might have problem with the Excel file name with a white space in it.
Try to copy the "Political 2008.xlsx" file to your current folder, re-name it so it doesn't contain white space in the name, change the Excel file name in the above code and run it again.

6 件のコメント

Titus Edelhofer
Titus Edelhofer 2011 年 12 月 20 日
Additionally: take a look at what "which xlsread" gives. Is it something like <matlab>\toolbox or some function of yours or a variable?
Titus Edelhofer
Titus Edelhofer 2011 年 12 月 20 日
And by the way: you will need to write linprog instead of LINPROG.
kelvin lee
kelvin lee 2011 年 12 月 20 日
i didnt know different excel versions will affect. i will take a look on that. @fangjun jiang, the white space didnt seem to have any effect. :/
@titus, i will take a look on that too. thanks for the LINPROG advice
Titus Edelhofer
Titus Edelhofer 2011 年 12 月 20 日
Hi Kelvin, one last question: in which line of the code does the error occur, in the line with "xlsread"?
Malcolm Lidierth
Malcolm Lidierth 2011 年 12 月 20 日
@Titus
My guess is not.
>> Political 2008.xlsx
Undefined function 'Political' for input arguments of type 'char'.
kelvin lee
kelvin lee 2011 年 12 月 22 日
@Titus, what malcolm said was correct. its a undefined function problem. but im not sure what is wrong. i went back to check the values in the excel file to see if there are any blanks, but then all cells inside are filled. and still produce the same error code. troubled me. ):

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

kelvin lee
kelvin lee 2011 年 12 月 22 日

0 投票

hi guys. i have solved the problem. the solution is from all the answers you guys have helped. thank you so much.
first, i have to remove the blank space in the .m file. to Political2008.m
then i converted the .xlsx file to .xls from Office 2007 to Office 2003.
finally changed LINPROG to linprog.
and i got it running. (:

1 件のコメント

Fangjun Jiang
Fangjun Jiang 2011 年 12 月 22 日
Interesting! I guess everyone has a lesson learned here.

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

カテゴリ

質問済み:

2011 年 12 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by