I'm trying to create this matrix where we have A = [xb.^2, xb, 1]. It will be a 3×36 matrix where I have found 36 values for xb.^2 and xb, and will have 36 1s in the matrix as well. I'm trying to put it all together right now, and I'm not sure how.
Here's what I have so far:
M = csvread('filename.csv',1,0); N = csvread('filename.csv',1,0); n = length(N(:,4)); m = length(M(:,4)); x = -1:1.8/36:0.8; for t = 1:36 a = 0; b = 0; ymsum = 0; ynsum = 0; for i = 1:n if -N(i,4) < x(t+1) && -N(i,4) > x(t) ynsum = ynsum + N(i,5); a = a+1; end end for o = 1:m if -M(o,4) <= x(t+1) && -M(o,4) >= x(t) ymsum = ymsum + M(o,5); b = b+1; end end xb(t) = (x(t)+x(t+1))/2; ymb(t,1) = ymsum/a; ynb(t,1) = ynsum/b; end
The matrix is ideally supposed to look like:
A = [xb(1).^2 xb(1) 1 xb(2).^2 xb(2) 1 xb(3).^2 xb(3) 1 . . . . . . . . . xb(36).^2 xb(3) 1]
It's probably really simple, but I'm not seeing it. Thank you.
Best Answer