cody Problem 1035. Generate a vector like 1,2,2,3,3,3,4,4,4,4

11 ビュー (過去 30 日間)
Jann B
Jann B 2019 年 2 月 2 日
編集済み: Farooq 2022 年 9 月 18 日
Dear Sir or Madam
I tried to solve the cody-problem namend in the title.
Could you pleas tell me how I should name the vektor/variable in which it should be presentet?
Thank you for helping me.
Yours faithfully
Jann Borlinghaus
  2 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 2 日
hint: the first letter of the function is r
John D'Errico
John D'Errico 2019 年 2 月 2 日
I'd suggest you need to learn how to write a function. Start by reading the getting started tutorials in MATLAB.

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

採用された回答

Cris LaPierre
Cris LaPierre 2019 年 2 月 2 日
The setup for the problem is already given to you:
function ans = your_fcn_name(n)
n
end
You final answer must be assigned to the variable shown to the left of the '='. As you can see, this function will return the value assigned to a variable named 'ans'.
This variable name can be changed to any valid variable name. Just be sure the variable used in your solution is the same.
  1 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 2 日
In addition to that a variable shouldn’t be named "ans"

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

その他の回答 (1 件)

Farooq
Farooq 2022 年 9 月 18 日
編集済み: Farooq 2022 年 9 月 18 日
you need to name the end vector as ans
so
ans = [.....]
I believe that will work.
But generally speaking, for your other MATLAB projects you should not name a variable as "ans" because it will make things very confusing for you. Use good names for variables so that you are able to understand the code every time you see it and so that others can understand it too. Maybe you visit your code 12 months later and you don't know what "ans" is. That's why appropriate names should be used.
Also "ans" is a default variable name given by MATLAB when no variable name is assigned by the user, so it could cause you problems if you use "ans" in your code.
I hope this helps!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by