MATLAB: DATA ANALYSIS

for loopmatrixmatrix arraymatrix manipulation

Hi,
I have a problem which is outlined below:-
x = 1:5;
y = 1:5;
t = -1:1/2:1;
u = 0:1/2:2;
I then calculate
for i = 1:5
z = y(:,i) - ( t(:,i) + ( u .* x(:,i) ) )
end
This then yields
z =
2.0000 1.5000 1.0000 0.5000 0
z =
2.5000 1.5000 0.5000 -0.5000 -1.5000
z =
3.0000 1.5000 0 -1.5000 -3.0000
z =
3.5000 1.5000 -0.5000 -2.5000 -4.5000
z =
4.0000 1.5000 -1.0000 -3.5000 -6.0000
I would like it to output in the form
z =
Columns 1 through 8
2.0000 1.5000 1.0000 0.5000 0 2.5000 1.5000 0.5000
Columns 9 through 16
-0.5000 -1.5000 3.0000 1.5000 0 -1.5000 -3.0000 3.5000
Columns 17 through 24
1.5000 -0.5000 -2.5000 -4.5000 4.0000 1.5000 -1.0000 -3.5000
Column 25
-6.0000
Is this possible please?
Any help would be greatly appreciated

Best Answer

  • I suggest going over the getting started documentation and taking a look at this
    x = 1:5;
    y = 1:5;
    t = -1:1/2:1;
    u = 0:1/2:2;
    y = repmat(y,5,[]);
    t = repmat(t,5,[]);
    z = y-(t+u'*x);
    z = z(:)'