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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by