フィルターのクリア

How to define array without size and append values

42 ビュー (過去 30 日間)
NoYeah
NoYeah 2020 年 4 月 14 日
コメント済み: NoYeah 2020 年 4 月 14 日
in C++, by using the vector API
we can create empty array and append values.
//for C++
vector<float> v;
v.push_back(2.3);
v.push_back(3.1);
v.push_back(4.5);
then we got
v[0]=2.3
v[1]=3.1
v[2]=4.5
How to implement that in Mathlab?
I have read the tutorial but it said the limited dimension is required when I want to create empty array
like
Array = int16.empty(5,0)

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 14 日
Array = [];
Array(end+1,1) = 2.3;
Array(end+1,1) = 3.1;
Array(end+1,1) = 4.5;
Caution: this is not as efficient as if you can pre-allocate. Every time you add on to the end, MATLAB has to create a new internal version of the array with one more slot in it, and copy the values from the old array to the new array and put on the new value. MATLAB is weak on growing-in-place
  1 件のコメント
NoYeah
NoYeah 2020 年 4 月 14 日
ookay thanks...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by