フィルターのクリア

i have 4 columns of (256x4 double) type.

1 回表示 (過去 30 日間)
mania online
mania online 2016 年 3 月 1 日
コメント済み: Roger Stafford 2016 年 3 月 3 日
I want to add column 1 with 3 and column 4 with 2 and need to store results in two columns. In first column it should save the result of 1 and 3 and in second column it should save 2 and 4 result. one more thing i want to add column 1 with 3 randomly.Like 1st index of column 1 need to add with any index of column 3. i don't want to add these columns with similar index

採用された回答

Roger Stafford
Roger Stafford 2016 年 3 月 1 日
B = A(:,1:2)+A(:,3:4);
  15 件のコメント
mania online
mania online 2016 年 3 月 2 日
got the point. Can you please tell me how to add column 1 with 3 randomly.Like 1st index of column 1 need to add with any index of column 3. i don't want to add these columns with similar index.
Roger Stafford
Roger Stafford 2016 年 3 月 3 日
I interpret your statement "add column 1 with 3 randomly.Like 1st index of column 1 need to add with any index of column 3. i don't want to add these columns with similar index" to mean that you seek a random permutation of column 3 which at no position from 1 to 256 does the permuted index value agree with the original position index value. For columns of length 256 the while-loop in the code below will probably require an average of two to four repetitions. If you wish the same action for columns 2 and 4, the following code can easily be modified to do that.
n = size(A,1);
b = true;
while b
p = randperm(n);
b = any(p==(1:n));
end
B(:,1) = A(:,1) + A(p,3);

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

その他の回答 (0 件)

カテゴリ

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