Send help for the world's easiest matlab code and for some reason I can't get it to work

1 回表示 (過去 30 日間)
Muhammed Ahkbar
Muhammed Ahkbar 2017 年 5 月 14 日
コメント済み: Walter Roberson 2017 年 5 月 14 日
function i = find_first(array, value)
% FIND_FIRST Find first index of a value in an array.
% I = FIND_FIRST(ARRAY, VALUE) returns the index I into the ARRAY where the
% first occurrence of VALUE is found. If VALUE is not in ARRAY, then an
% error is raised.
n = length(array);
i = 1;
while ??? && ???
i = i + 1;
end
%Check if value was not found
if ???
error('VALUE was not found.');
end
I can't do it. What are the question marks supposed to be?
  1 件のコメント
Muhammed Ahkbar
Muhammed Ahkbar 2017 年 5 月 14 日
>> find_first([2,7,1,8,2,8,1], 8)
This is an example question for the function

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

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 5 月 14 日
while your index is not past the end of the vector and the current value is not the match you are looking for
if your index is past the end of the vector
  6 件のコメント
mitch midalia
mitch midalia 2017 年 5 月 14 日
Thank you very much, but I still don't understand why my function earlier wasnt working. Could you please explain? Thanks :)
Walter Roberson
Walter Roberson 2017 年 5 月 14 日
i <= n & array(i) ~= value

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by