Help needed on error!!!!!
2 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Walter Roberson
on 13 Feb 2012
Ouch! Ouch!
if inputarg(j).(fieldname) < inputarg(low).(fieldname)
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!