Remove element from array but want to keep in indices

1 回表示 (過去 30 日間)
NA
NA 2018 年 10 月 9 日
コメント済み: Walter Roberson 2018 年 10 月 9 日
A=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13; 7 8;7 9;9 10;9 14;10 11;12 13;13 14] I omit the second row: A(2,:)=[]; so size A changes to 19*2 and [2,3] changes to my second element. If I want to keep [2,3] as a third element, what should I do?
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 10 月 9 日
Can you elaborate your question exactly? Use Maths to explain your problem.

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

回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2018 年 10 月 9 日
  2 件のコメント
NA
NA 2018 年 10 月 9 日
Thank you. the problem is that after omitting that row I used it as a input of my function. so give me this error: Error using grValidation (line 21) 1st and 2nd columns of the array E must be positive! Is there any other way instead of nan?
Walter Roberson
Walter Roberson 2018 年 10 月 9 日
No, that is a validation routine from the Graph Theory Toolbox from the file exchange, and that Toolbox does not support omitted elements.

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


Walter Roberson
Walter Roberson 2018 年 10 月 9 日
To keep that row as being the third row... don't remove the second row.
The alternative is to use containers.map to create mappings between subscripts and values. Then when you delete keys from the map, the remaining items would keep the same keys.
.... But what you probably need to hear is:
Run your loop backwards so that you delete rows starting from the end. The rows after will "fall down" into the earlier slots, but that is okay because next iteration you will be examining a slot that has not had an opportunity to fall down because it was below all slots you looked at before that.

madhan ravi
madhan ravi 2018 年 10 月 9 日
編集済み: madhan ravi 2018 年 10 月 9 日
A(2,:)=0
Did it work?
  3 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 9 日
Can you upload your code!
Walter Roberson
Walter Roberson 2018 年 10 月 9 日
That toolbox does not support omitted nodes.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by