A function that inserts an element into an array

2 ビュー (過去 30 日間)
Seong Ho Yang
Seong Ho Yang 2020 年 9 月 14 日
コメント済み: Seong Ho Yang 2020 年 9 月 14 日
So I am doing my homework on MatLab and I am baffled by this question given. It is to write a script that enters an element into an array at an index.
The array(A)'s size is 1 by N. The element(e) is the value that is entered. index(i) is the ith position of the array.
No specific array is provided.
All I know is that after the element has bee added the size of the array is now 1 by (N+1)
But beyond this, I don't even know where to start.
Please help! (explanation would be appreciated too!)
*note : this is an introductory class. So far, I have only covered functions, arrays
  3 件のコメント
Seong Ho Yang
Seong Ho Yang 2020 年 9 月 14 日
This is what I have so far. I have no idea how to start the script and I have no idea how to index
Stephen23
Stephen23 2020 年 9 月 14 日

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

採用された回答

KSSV
KSSV 2020 年 9 月 14 日
Hints:
  1. To get length of an array use length.
  2. To get dimensions use size.
  3. If you have an array a, to access ith element: a(i)
  4. I can join two rwo arrays using [a b]
  5. I can join selected elements of a using [a(1:3) a(4) a(5:end)]
Try all the above steps in command window, you will get an idea how to complete your Home Work. Concentrate on the 5th point.
  1 件のコメント
Seong Ho Yang
Seong Ho Yang 2020 年 9 月 14 日
Thank you so much! This really helped me !

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

その他の回答 (0 件)

カテゴリ

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