I think you've mostly got it. One key point to note is your sampling frequency is monthly, so 12 times per year. If you want the trend in units of sea level height per year, then the correct way to calculate it is:
[matrix_trend,p] = trend(matrix, 12, 'omitnan');
If you're trying to detrend the data, you've got it right, except I wouldn't use detrend as a variable name, because that might get confused with a function called detrend. It's probably better to do:
ssh_detrend = detrend3(ssh, 'omitnan');
Just one more note regarding your nans: I assume you have a lot of nans up north due to presence of sea ice and perhaps due to the orbital limit of whatever altimeters you're using. The 'omitnan' option should work properly, but when interpreting results, know that the results will represent the trend of the available data. So if a given grid cell only has data for the last ten years of the record, then the trend function will only tell you about the trend over the past ten years in that grid cell. This could potentially paint a picture of more extreme trends at the poles, in comparison to low-latitudes where data are available for the full record. But again, if the data span the full timespan of record but are just spotty due to perhaps an intermittent presence of sea ice, that should be alright.