フィルターのクリア

Debugging a piece of code

1 回表示 (過去 30 日間)
Federico Gremmo
Federico Gremmo 2020 年 11 月 3 日
編集済み: per isakson 2020 年 11 月 28 日
I have been trying to run a piece of code written in Matlab that contains the following:
function list = shellsort(list);
interval = floor(length(list)/3);
I get the following error message:
Not enough input arguments.
Error in shellsort (line 3) interval = floor(length(list)/3);
Any ideas on how to debug it?

回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 11 月 3 日
When you press the green Run button, what is your expectation about where MATLAB will search for the value of the variable named list ?
  2 件のコメント
Federico Gremmo
Federico Gremmo 2020 年 11 月 3 日
編集済み: per isakson 2020 年 11 月 28 日
This is the whole code. however, I get the error message on the line of the line "interval = floor(length(list)/3);"; so I take it that Matlab thinks there is something wrong with the floor function.
function list = shellsort(list);
interval = floor(length(list)/3);
while (interval > 0)
for i = interval:length(list)
temp = list(i);
j = i;
while ((j < interval) & (list(j - interval) > temp))
list(j - interval) = list(j);
j = j - interval;
end % while
temp = list(j);
end %for
interval = floor(interval/2);
end % while
end % shellsort
Walter Roberson
Walter Roberson 2020 年 11 月 5 日
You are pressing the green Run button to initiate the code. MATLAB needs to know the value of the variable named list in order to proceed. Where are you expecting MATLAB to look to find the variable named list?

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


Monika Jaskolka
Monika Jaskolka 2020 年 11 月 3 日
How are you running the shellsort function? From the error message you provided, it looks like you are not giving shellsort any input parameters
% Incorrect
>> shellsort
Not enough input arguments.
Error in shellsort (line 2)
interval = floor(length(list)/3);
% Correct
>> shellsort(list)
ans =
1 2 3
  15 件のコメント
Federico Gremmo
Federico Gremmo 2020 年 11 月 5 日
I need to use this particular one. The problem is that I have never used Matlab before, so I do not know how to step through the program. If you could share the three changes with me, it would be great. If not, too bad.
Rik
Rik 2020 年 11 月 5 日

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by