フィルターのクリア

Replacing values in a column vector.

2 ビュー (過去 30 日間)
Fayyaz
Fayyaz 2014 年 7 月 7 日
回答済み: Azzi Abdelmalek 2014 年 7 月 7 日
Hello.
I've a column vector 61312*1. Values ranges from 0 to 20. I need to replace the values (0 to 20) with the below mentioned values(0 to 7):
0=0, 1=1, 2,3=2, 4=3, 5,6,13=4, 7,8,9=5, 10,11,12,16=6, 14,15,17,18,19,20=7
Thanks in advance.
  2 件のコメント
Robert Cumming
Robert Cumming 2014 年 7 月 7 日
what have you tried?
Fayyaz
Fayyaz 2014 年 7 月 7 日
I was trying to get idea from matlab "find and replace substring" but don't understand how to apply to this case.

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 7 日
A=randi([0 20],20,1) % Example
a1={0 1 [2 3] 4 [5 6 13] [7 8 9] [10 11 12 16 ] [14 15 17 18 19 20]} % Numbers to be replaced
b1=[0 1 2 3 4 5 6 7] % Numbers that will replace your original array
idx=cellfun(@(x) ismember(A,x),a1,'un',0)
for k=1:numel(idx)
A(idx{k})=b1(k)
end

その他の回答 (1 件)

Robert Cumming
Robert Cumming 2014 年 7 月 7 日
Your dealing with a matrix - which I assume contains numeric data, so look up the help and examples for find and ideally logical indexing.
Finding out how to do this yourself will teach you a lot more than me giving you the answer.
  1 件のコメント
Fayyaz
Fayyaz 2014 年 7 月 7 日
OK thanks. Let me try on logical indexing.

サインインしてコメントする。

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by