MATLAB: How to remove elements from a matrix

elements

I would like to delete random elements from this matrix: U = [ 't' 'h' 'e' 's' 't' 'r' 'i' 'n' 'g']
How can i do it?

Best Answer

If you have the Statistics and Machine Learning Toolbox, you can do
numberToKeep = 4;
U = U(sort(randsample(length(U),numberToKeep)));
If you do not have that toolbox, you can accomplish the same thing using a different random function, like randi, but you'll need to guard against repeated elements. Let us know if you get stuck.