Replacing elements in matrix columns

2 ビュー (過去 30 日間)
Fayyaz
Fayyaz 2015 年 4 月 14 日
回答済み: Chris McComb 2015 年 4 月 14 日
Hi,
I have a matrix 61312*3, and I want to replace the element of the 2nd and 3rd column by some numbers. For example, in 2nd and 3rd column, I need to replace
34 by 1
10, 17, 22, 39, and 59 by 2
and so on.
How should I proceed? Thanks in advance.

回答 (1 件)

Chris McComb
Chris McComb 2015 年 4 月 14 日
You can do the replacement using logical indexing. The replacement for 34 --> 1 would be as follows:
for i=2:3
idx = (mat(:,i) == 34);
mat(idx,i) = 1;
end

カテゴリ

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