Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
Hi all,

I'm looking for an algorithm to delete a specific row in a matrix. For example, matrix [J]:

[row1 - position 1
row2 - position 2
row3 - position 3
row4 - position 4
row5] - position 5

My current method is to continually swap rows until the row that needs to be deleted is at position 5, and then set the dimensions of [J] to 4. However, whenever I do this, it just deletes row 5.

Example run:
Try to delete row 2
position 2 and 3, swap
position 3 and 4, swap
position 4 and 5, swap

should now be

row1
row3
row4
row5
row2

Any help? Sorry if my explanation sucks, but I have no wish to send screenshots and stuff. I've verified that my code syntax and stuff is correct... maybe the way I swap rows isn't working?

-SW11
I'm 99% sure you're using the rowSwap( command as if it swaps the rows of the matrix in place. However, rowSwap( doesn't modify the matrix you call it on. It just returns the row-swapped matrix. For example:

Code:
```[[1,2][3,4→[A]          [[1 2]           [3 4]] rowSwap([A],1,2          [[3 4]           [1 2]] [A]          [[1 2]           [3 4]]```

You'll need to store the swapped matrix back into [A] to save it for the next swap.
If you're using this in a place where you could put

Code:
``` If [M](x,y)=0 ```

to make the data effectively deleted, you could just store 0 into the desired cell in the matrix.
lirtosiast wrote:
I'm 99% sure you're using the rowSwap( command as if it swaps the rows of the matrix in place. However, rowSwap( doesn't modify the matrix you call it on. It just returns the row-swapped matrix. For example:

Code:
```[[1,2][3,4→[A]          [[1 2]           [3 4]] rowSwap([A],1,2          [[3 4]           [1 2]] [A]          [[1 2]           [3 4]]```

You'll need to store the swapped matrix back into [A] to save it for the next swap.

Oh! Gotcha, thanks a lot. I'll modify my code to implement this.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are GMT - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Advertisement