フィルターのクリア

i have S 300x800 data set matrix , i need code for replacing coloumns

1 回表示 (過去 30 日間)
ihab
ihab 2017 年 12 月 31 日
コメント済み: Star Strider 2017 年 12 月 31 日
i have S 300x800 data set matrix , i need code for replacing column 120 with 50,and 120 with 121,and 240 with 100 and 240 with 241 ,and 360 with 150 and 360 with 361,.. what is the easy way of doing it with large data set 50 matrix of 300x800 each ?
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 31 日
I notice that you have listed two replacement columns for each column. Are you looking to replace one column each time?
ihab
ihab 2017 年 12 月 31 日
no, i am switching between columns, switch 120 with 50 ,240 with 100, 360 with 150, 200 with 480, 250 with 600

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

採用された回答

Star Strider
Star Strider 2017 年 12 月 31 日
I cannot claim that this is completely robust since I’ve experimented only with this code. I appears to do the same operation in one line, without the loops:
M = bsxfun(@times, ones(5,7), (1:7)) % Create Matrix
M(:,[2 5 7]) = M(:, [7 2 5]) % Switch Col#7 With Col#2, Col#2 With Col#5, Col#5 With Col#7
M =
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
M =
1 7 3 4 2 6 5
1 7 3 4 2 6 5
1 7 3 4 2 6 5
1 7 3 4 2 6 5
1 7 3 4 2 6 5
Experiment with it to see if it does what you want with your matrix.
  2 件のコメント
ihab
ihab 2017 年 12 月 31 日
thank you very much, i really appreciate it
Star Strider
Star Strider 2017 年 12 月 31 日
As always, my pleasure.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 31 日
to_replace = 120:120:800;
for K = 1 : length(to_replace)
temp = OriginalMatrix;
temp(:,to_replace(K)) = temp(:,K*50);
NewMatrix{2*K-1} = temp;
temp = OriginalMatrix;
temp(:,to_replace(K)) = temp(:,to_replace(K)+1);
NewMatrix{2*K} = temp;
end

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by