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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by