Adding new column to a matrix with the same number repeated
71 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have a feeling this is really simple to do, because it seems that way in my mind, but for the life of me I can't figure out how to do it.
I have a 469x1 matrix (interNode) and I want to make a second column with all rows having the same value (2) to give me a 469x2 matrix.
Any help would be appreciated :)
0 件のコメント
採用された回答
KSSV
2016 年 11 月 28 日
interNode = rand(469,1) ; % a radnom data
c2 = 2*ones(size(interNode)) ; % second column to add
iwant = [interNode c2] ;
その他の回答 (2 件)
Preethi
2016 年 11 月 28 日
hi,
hope this helps
a= [1;2;3;4;2;3;2;6;7;2]
a(:,2)=zeros(length(a),1);
a(find(a(:,1)==2)+length(a(:,1)))=2
0 件のコメント
Elias Gule
2016 年 11 月 28 日
Hi, let's try this:
[nRows,nCols] = size(yourMatrix);
yourMatrix = [yourMatrix 2*ones(nRows,1)]; % This is called matrix horizontal concatenation.
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!