It is generally a bad idea to use names for variables that are already useful function names. So here rem is one such bad idea. The rem function is similar to mod, in fact, though it behaves differently in some subtle respects. Regardless, you will do well to avoid such things.
But why did your code fail? In fact, you have the right idea. Where you failed was in the first step. You did this:
rem = mod(text,4);
text = text(1:end- rem);
The problem is you did not know what to apply mod to. You needed to take the modulus of the LENGTH of text. Text is a string vector. If you take the mod of the string itself, then expect problems.
In fact, I think you meant a character vector, not a string. Be careful here, as there is now a new class in MATLAB, called a string. It is created using double quotes. A character vector is created using single quotes. But the way you are using the text vector suggests that you have a character vector, so I will assume that to be the case. For example...
text = 'The quick brown fox jumps over the lazy dog'
'The quick brown fox jumps over the lazy dog'
So text is a vector, of length 43. You want to reduce it to a length that is a multiple of 4. You cannot take the mod of text itself, but of the length of text, or the number of elements in text. The numel function tells how many total elements in the vector or array. For vectors, length applies too.
So what you might do is
numtext = length(text);
numdiscarded = mod(numtext,4);
text = text(1:end - numdiscarded);
'The quick brown fox jumps over the lazy '
As you can see, we dropped the last three characters in the vector, here, the word dog. Leaving a less complete sentence, but that is a bit irrelevant. ;-) You could have done it in one line of course, simply by compressing it all into one line, but that tends to create less readable code. I strongly recommend the use of uncompressed code. Use extra variables, IF they will make your code more clear and easy to read. That also makes your code easier to debug later on. So, while this:
text = text(1:end - mod(numel(text),4));
does work, I'd suggest the first form is a better programming style.