What is wrong with this array

2 ビュー (過去 30 日間)
Blair Hall
Blair Hall 2017 年 10 月 2 日
コメント済み: Walter Roberson 2017 年 10 月 2 日
function countValues = CreateArray(endValue)
% endValue: Ending value of array countValues
% Construct a row array countValues from 1 to endValue,
% using the double colon operator
countValues1 = [1:5]
countValues2 = [1:8]
end
  2 件のコメント
per isakson
per isakson 2017 年 10 月 2 日
編集済み: per isakson 2017 年 10 月 2 日
  • countValues, countValues1 and countValues2 are three different variables.
  • The input argument, endValue, is not used
  • Why 5 and 8 ?
  • Homework, I assume. The code in your question, is it a template provided by your teacher?
Walter Roberson
Walter Roberson 2017 年 10 月 2 日
What is the "double colon operator" ? Is that the general form for the colon operator, A : B : C ?

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

回答 (1 件)

Jan
Jan 2017 年 10 月 2 日
編集済み: Jan 2017 年 10 月 2 日
The instruction is clear:
Construct a row array countValues from 1 to endValue
But you create two arrays called countValues1 and countValues2, which are going from 1 to 5 or to 8, respectively. Construct one array, which is called "countValues" and goes from 1 to endValue. Now all you have to do is to translate "to" to the colon operator and insert a "=".
You do not need the square brackets, because they are the operator for a concatenation. But 1:5 is a vector already and no concatenation is needed.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by