How to create a 1x2 row vector names AB that stores A as the first entry and B as the scond entry?
28 ビュー (過去 30 日間)
古いコメントを表示
A = [1; 2; 3; 4; 5]
B = [1; 2; 3; 4]
How to create a 1x2 row vector names AB that stores A as the first entry and B as the scond entry?
0 件のコメント
回答 (1 件)
John D'Errico
2022 年 2 月 20 日
Since this is impossible in the most basic sense, I assume it is not homework.
Simple matrices in MATLAB cannot store a variable number of elements, or a multiple number of elements in each position.
However, it is possible. You just need to learn about the alternaitve type of arrays in MATLAB. In this case, a cell array is perfect.
A = [1; 2; 3; 4; 5];
B = [1; 2; 3; 4];
AB = {A,B}
Now you can access either of those vectors simply as
AB{1}
AB{2}
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!