display Empty matrix: 1-by-0

20 ビュー (過去 30 日間)
david Chan
david Chan 2014 年 10 月 26 日
コメント済み: Mohammad Abouali 2014 年 10 月 26 日
here is the question :
function can return a vector as a result. Write a function vecout that will receive
one integer argument and will return a vector that increments from the value of
the input argument to its value plus 5, using the colon operator.
I got : function vector= vecout(integer)
start= integer;
end= integer + 5;
vector= start:end;
end
The answer display Empty matrix: 1-by-0 What should I fix this porblem

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 10 月 26 日
編集済み: Mohammad Abouali 2014 年 10 月 26 日
This is very tricky
You can not use end as a variable name. That is a reserved word.
SO pretty much your definition of the function:
function vector= vecout(integer)
start= integer;
end = integer + 5;
vector= start:end;
end
becomes:
function vector= vecout(integer)
start= integer;
end
everything after the first "end" is ignored so vector is never assigned anything; thus returning as an empty array.
Correct it this way
function vector=vecout(n)
vector=n:n+5;
end
  4 件のコメント
david Chan
david Chan 2014 年 10 月 26 日
I get it thank you for your answer
Mohammad Abouali
Mohammad Abouali 2014 年 10 月 26 日
You are welcome

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

その他の回答 (0 件)

カテゴリ

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