First column matrix into ones

조회 수: 1 (최근 30일)
Y LIN
Y LIN 2022년 3월 5일
댓글: Y LIN 2022년 3월 5일
Hello! How to extract the first coulmn of the matrix and make it ones?
For exmaple:
X = [1 4; 2 2; 3 6];
y = ones(X(:,1));
but it seems not work.
Thanks advanced for your help!
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 3월 5일
Okay, X(:,1) would be [1;2;3] .
Now what do you mean by "make it ones" ? Are you asking for a vector of ones with the same number of entries as there are rows in the table? Are you asking that afterwards X would be
1 4
1 2
1 6
??
Y LIN
Y LIN 2022년 3월 5일
Hello! Thanks for your reply. I'd like to extract only first column of the matrix, like example 3x2 into 3x1 and then make it all value as 1. How can I do that?

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

채택된 답변

Torsten
Torsten 2022년 3월 5일
편집: Torsten 2022년 3월 5일
X = [1 4; 2 2; 3 6];
X(:,1) = 1
or
y = ones(size(X,1),1)
depending on how your question is meant.
  댓글 수: 2
Y LIN
Y LIN 2022년 3월 5일
Hello! Thanks for your reply. I'd like to extract only first column of the matrix. Like example 3x2 extract 3x1 and then make all value as 1. How can I do that?
Y LIN
Y LIN 2022년 3월 5일
Oh, sorry for late refreshing the page! It works! Thank you so much for your help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by