Adding new column to a matrix with the same number repeated

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 :)

 채택된 답변

KSSV
KSSV 2016년 11월 28일
interNode = rand(469,1) ; % a radnom data
c2 = 2*ones(size(interNode)) ; % second column to add
iwant = [interNode c2] ;

댓글 수: 1

Thank you :) very simple but I just couldn't think of it! Must be Monday mornings!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Preethi
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
Elias Gule
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.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2016년 11월 28일

답변:

2016년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by