フィルターのクリア

How do I add a column to a matrix with specific values?

1 回表示 (過去 30 日間)
Z
Z 2013 年 7 月 8 日
If I have a matrix like so:
1 2 3 4
5 2 6 7
3 6 5 7
How can I add a third column with a value of one for every row that has a value of 2 in the second column? Thanks!

採用された回答

Z
Z 2013 年 7 月 8 日
Never mind, I found out that this is the syntax:
mydata (mydata (:,2) == 2,4) = 1;

その他の回答 (1 件)

Greg Heath
Greg Heath 2013 年 7 月 10 日
The question is ill posed.
The matrix has 4 columns and the question is how to add a third column.
The accepted answer is incorrect.
It replaces components in the fourth column
1. Bad question
2. Bad answer.
It should be flagged.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by