Dear all, For a given matrix (square) i need to eliminate some elements (some rows and columns)
A =
35 6 19
3 7 23
31 2 27
I need only the second (not the first and the third) row and column : the eliminated are stocked in a vector
B = (1 3)
So : some function (A, B) :::> the result C = 7
function (A, B) = C

2 件のコメント

KSSV
KSSV 2017 年 4 月 6 日
iwant = A(2,2)
wont it solve the purpose?
Lila wagou
Lila wagou 2017 年 4 月 6 日
Dear KSSV, i need a function for lot of use
A1 =
35 6 19
3 7 23
31 2 27
and
B1 = (1 3)
C1 = 7
or
A2 =
35 6 19 11
3 7 23 44
31 2 27 55
31 2 27 55
and
B2 = (2 3)
C2 =
35 11
31 55

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

 採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 4 月 6 日

0 投票

ii = num2cell([1;1]*setdiff(1:length(A),B(:)'),2);
out = A(ii{:});

8 件のコメント

Lila wagou
Lila wagou 2017 年 4 月 6 日
Dear Andrei; please why 2 in ,B(:)'),2); thanks
Andrei Bobrov
Andrei Bobrov 2017 年 4 月 6 日
編集済み: Andrei Bobrov 2017 年 4 月 6 日
Please read about num2cell, it's 'dim'.
Lila wagou
Lila wagou 2017 年 4 月 6 日
Dear Andrei; thanks the explication, is it possible to get only the the first and the third (not the second) rows and columns : the wanted are stocked in a B vector
A =
35 6 19
3 7 23
31 2 27
B = (1 3)
C = function (A, B)
C =
35 19
31 27
Andrei Bobrov
Andrei Bobrov 2017 年 4 月 7 日
C = A(B,B)
Lila wagou
Lila wagou 2017 年 4 月 7 日
Dear Andrei; Thank you a lot for your valued assistance.
judy abbott
judy abbott 2017 年 4 月 7 日
Hy Lila, Hy Andrei Bobrov, i have a same need but for a vector, for a V_old vector i want to insert the V_ins vector in the order of V_ord vector (the value of 10 replace the 1 element of V_old, the value of 20 replace the 3 element of V_old):
V_old = zeros(1,3);
V_ins = [10 20];
V_ord = [1 3];
I want to write a function
V_new = MyFunction(V_old, V_ins, V_ord)
to get V_new = 10 0 20
Thank
Andrei Bobrov
Andrei Bobrov 2017 年 4 月 7 日
V_new = V_old;
V_new(V_ord) = V_ins;
Lila wagou
Lila wagou 2017 年 4 月 7 日
Dear Andrei; please how to trait a vector (eliminate the elements stocked in a vector by order)
A = [10 52 33]
B = [3]
ii = num2cell([1]*setdiff(1:length(A),B(:)'),1);
out = A(ii{:});
i get out = 52 so i must get out = 10 52

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2017 年 4 月 6 日

0 投票

C=A;
C(B,:)=[];
C(:,B)=[]

3 件のコメント

Andrei Bobrov
Andrei Bobrov 2017 年 4 月 6 日
Hi Fangjun!
Jan
Jan 2017 年 4 月 7 日
Yes, hi Fangjun!
Fangjun Jiang
Fangjun Jiang 2017 年 4 月 7 日
Hello, friends!

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

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by