MATLAB: A little help

matrix manipulation

Hi there,
I am having a little problem with one of the questions for an assignment I have. I have less than basic knowlage of MALAB so this assignment is to break me in so to say.
The question states that I need to create a matrix with with the input values clamped in the range +- 1.
Any help would be much appreciated! 😀

Best Answer

Aadam: Based on your latest comment to your original question I would just make my code into a function. In file test.m:
function test()
% Generate sample data.
M = 10*rand(8) - 5; % Sample matrix.
% Clip the data to the range -1 to +1
oneabs = Clip(M)
% Clip to range (-1 to +1) if outside that range.
% Leave values alone if within that range.
function oneabs = Clip(M)
oneabs = M; % Initialize.
oneabs (M < -1) = -1;
oneabs (M > 1) = 1;