“A=[A,B{i}];”

5 ビュー (過去 30 日間)
Thabani Khuzwayo
Thabani Khuzwayo 2018 年 10 月 30 日
コメント済み: Stephan 2018 年 10 月 30 日
A = [A, B{i}];
Could someone please explain what this line of code does...I can’t find such syntax in the Help Files. Thanks

採用された回答

Stephan
Stephan 2018 年 10 月 30 日
編集済み: Stephan 2018 年 10 月 30 日
Try to understand what the following code does:
A = [1, 2] % define a vector of dimension 1x2
B = {[3, 4], [5, 6]} % define a cell array containing 2 vectors of dimension 1x2
B1 = B{1} % show the vector in position 1 of the cell array B
B2 = B{2} % show the vector in position 2 of the cell array B
for k = 1:2 % start a for loop over the length of the cell array B
A = [A, B{k}] % in every step of the loop append the k'th element of cell array B to A
end % finish the for loop
the result is:
A =
1 2
B =
1×2 cell array
{1×2 double} {1×2 double}
B1 =
3 4
B2 =
5 6
A =
1 2 3 4
A =
1 2 3 4 5 6
Copy this code and play with the values - im pretty sure after some tries you got it - it is easy if you understood it once.
Best regards
Stephan
  2 件のコメント
Thabani Khuzwayo
Thabani Khuzwayo 2018 年 10 月 30 日
I tried it & I understand. Thank you
Stephan
Stephan 2018 年 10 月 30 日
Please accept helpful answers in order to help other people with similar problems finding useful answers.
Best regards
Stephan

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

その他の回答 (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