ماهي المشكله في الكود هذا ؟

function position = indexOf(value, inputArray)
position = -1; % sets index to -1, number not yet found in array
for i = 1: length(inputArray)
i % this line shows how many times the for loop runs
if value == inputArray(i)
position = i
return; % return stops the loop if the number is % found
end
end
عند تشغيل هذه الداله البرنامج يعطيني رساله الخطا التاليه
Undefined function or method ‘indexOf’ for input arguments of
type ‘double’.
الغرض من الكود هو مقارنه الرقم في المتغير value بالارقام في المصفوفه inputArray

أخي بالبداية لازم تبعت قيم value, inputArray
position = indexOf(value, inputArray)

من برنامج الماتلاب نفسو مثلاً ارسل قيم position = indexOf(5,10)

وعندك هاد الشرط غلط if value == inputArray(i)
ال inputArray رقم يعني ما الها اندكس واحد واثنين وهيك

if value == (i) هيك صح

وبالتوفيق

منتظر اجابات اخرى

لا يوجد أى مشكلة على الأطلاق فى الدالة


function position = indexOf(value, inputArray)
position = -1; % sets index to -1, number not yet found in array
for i = 1: length(inputArray)
i % this line shows how many times the for loop runs
if value == inputArray(i)
position = i
return; % return stops the loop if the number is % found
end
end

>> x = [1 2 3 4 5 6 7 8 9];
>> indexOf(5, x)

i =

     1


i =

     2


i =

     3


i =

     4


i =

     5


position =

     5


ans =

     5