Help needed on error!!!!!

1 次查看(过去 30 天)
newiuht
newiuht 2012-2-13
Hi guys,
I've got this error expression.. can someone help vet through my script and see what's wrong? thanks.
Script:
function outv = generalPackSort (inputarg, fieldname)
if isfield(inputarg, fieldname)
for i =1:length(inputarg) -1
low = i;
for j= i + 1:length(inputarg)
if eval (['inputarg ('int2str(j)').'fieldname])< ...
eval (['inputarg ('int2str(low)').'fieldname])
low = j;
end
end
%Exchange elements
temp = inputarg(i);
inputarg(i)=inputarg(low);
inputarg(low) = temp;
end
outv = inputarg;
else
outv = [];
end
end
Command window:
>> packByPrice = generalPackSort (packages, 'price')
??? Error: File: generalPackSort.m Line: 6 Column: 38
Unexpected MATLAB expression.
The error is in "if eval (['inputarg ('int2str(j)').'fieldname])< ...". But I can't figure out what's wrong.

回答(1 个)

Walter Roberson
Walter Roberson 2012-2-13
Ouch! Ouch!
if inputarg(j).(fieldname) < inputarg(low).(fieldname)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by