필터 지우기
필터 지우기

How to delete contents of matrix only if it has 2 elements?

조회 수: 1 (최근 30일)
Asher Zaidi
Asher Zaidi 2018년 6월 11일
댓글: Asher Zaidi 2018년 6월 11일
If p = [55;56], and I want to set it to one value (ex. p = 55), how can I write an "if" statement that does this using elements? As of now, I can only do it with this specific condition, but I would like to write "if p has more than one element, then set p equal to the first element." Code:
if p == [55;56]
p(2) =[]
end

채택된 답변

Matt J
Matt J 2018년 6월 11일
편집: Matt J 2018년 6월 11일
No need for an if-statement. Just do,
p(2:end)=[];
or
p=p(1);

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by