How to append a vector to a cell array?
60 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
Jan
2022 年 3 月 29 日
編集済み: Jan
2022 年 3 月 29 日
C = {[1,4,1], 0:10}; % The cell
v = linspace(1, 10, 100); % The vector
C{end + 1} = v;
% Or:
C{numel(C) + 1} = v;
% Or slower and less elegant:
C = cat(2, C, {v})
3 件のコメント
Jan
2022 年 3 月 29 日
編集済み: Jan
2022 年 3 月 29 日
In exactly the shown way:
C = {[1,4,1], 0:10}; % The cell
v = linspace(1, 10, 100); % The first vector
w = rand(1, 17); % The second vector
... % Equivalent for more vectors
C{end + 1} = v;
C{end + 1} = w;
% Or:
C = cat(2, C, {v, w})
% Equivalent:
nC = numel(C)
C(nC + 1:nC + 2) = {v, w};
その他の回答 (1 件)
Voss
2022 年 3 月 29 日
% A cell array of vectors, C:
C = {[1 2 3]; [1 2 3 4 5]; [1; 2; 3; 4; 5; 6]}
% Append a new vector to the end of C:
new_vector = 1:10;
C{end+1} = new_vector
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!