Message Boards Message Boards

0
|
6418 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Delete rows of a matrix that do not satisfy a certain condition?

Posted 6 years ago

Hello. I generate a matrix of outcomes. Suppose we have 10,20,30 values. I need to delete unnecessary rows of the matrix. My idea is to multiply 10 by the second column, 20 by third column,, 30 by fourth column. After that I delete all rows which do not satisfy the condition. for n-1, we remove all rows where an element has the value more than 30, for n-2 more than 50, for n-3 more than 60. But I can't even get 10,20,30 multiplied to second, third and fourth columns. Please, help me. Thanks in advance!

Regards,

Alex

Attachments:
POSTED BY: Alex Graham
6 Replies
Posted 6 years ago

Well I make some progress, the only questions I have now. How to delete rows which are more 60(forth column)?

{"0", "0", "0", "0"},
{"10", "0", "0", "10"},
{"0", "20", "0", "20"},
{"0", "0", "30", "30"},
{"20", "0", "0", "20"},
{"0", "40", "0", "40"},
{"0", "0", "60", "60"},
{"10", "0", "0", "10"},
{"0", "20", "0", "20"},
{"0", "0", "30", "30"},
{"30", "0", "0", "30"},
{"0", "60", "0", "60"},
{"0", "0", "90", "90"},
{"20", "20", "0", "40"},
{"20", "0", "30", "50"},
{"10", "40", "0", "50"},
{"10", "0", "60", "70"},
{"0", "40", "30", "70"},
{"0", "20", "60", "80"},
{"10", "20", "30", "60"}
POSTED BY: Alex Graham

Alex,

Look at Select[].

If your lst is numbers and not strings:

Select[lst, #[[4]] <= 60 &]

Regards,

Neil

POSTED BY: Neil Singer
Posted 6 years ago

Thank you so much for your reply. Could you please give me another hint on how to delete each forth element from the list.

{{0, 0, 0, 0}, {10, 0, 0, 10}, {0, 20, 0, 20},
mat12 = Delete[lst, 4]

This comand dosent work in this case.

POSTED BY: Alex Graham
Posted 6 years ago

And how to add a column to specific place, for example, in the middle. ,this adds a column to the end

MapThread[Append , {sr11, Table[0, Length[sr11]]}] Insert dosent work for this case

Regards,

POSTED BY: Alex Graham

Alex,

You need to Map the Delete:

Delete[4] /@ lst

or

Map[Delete[4], lst]

Regards,

Neil

POSTED BY: Neil Singer

Alex,

There is extensive documentation on adding and taking rows and columns of matrices. Look at the part options and the matrix and vector operations guide.

For example,

lst[[All, 2]]

Is the second column. You can also set the second column with

lst[[All, 2]] = {....}
POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract