Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ 1 1 1 1 2 4 8 2 1 1 1 1 2 1 1 2 ]
- [ 1 . 1 . 3 . 6 . 1 . 1 . 2 . 1 . ]
- [ 1 . . . 3 . . . 1 . . . 2 . . . ]
- [ 1 . . . . . . . 1 . . . . . . . ]
- % initialize the matrix of sampled data
- indx = 1;
- data = NaN(5, 128);
- for row=1:5
- for col=1:128
- if ( mod(col-1, indx) == 0)
- data(row, col) = rand();
- end
- end
- indx = power(2, row);
- end
- % Linearize the data in each row to overcome NaN entries
- for row=1:5
- fprintf('Linear interpolation for row %dn', row);
- indx = NaN;
- for col=1:128
- if (data(row, col) ~= NaN) || (col == 128)
- if isnan(indx)
- % initalize first point
- indx = col;
- elseif isnan(data(row,col)) && (col ~= 128)
- % ignore NaN values between 1 and N-1
- elseif ((col-1) ~= indx)
- fprintf('Creating linspace from col=%d to indx=%dn', col, indx)
- if (col == 128)
- % first row will always contain all points
- v = linspace(data(row, indx), data(1, col), col+1-indx);
- else
- v = linspace(data(row, indx), data(row, col), col+1-indx);
- end
- i=1;
- for j=indx:col
- data(row,j) = v(i); % update our data
- i = i + 1; % increment counter
- end
- indx = col;
- elseif ((col-1) == indx)
- indx = NaN;
- end
- end
- end
- end
- % Populate the X and Y vectors, X is columns, Y is rows, Z is data
- xmin = 1;
- ymin = 1;
- xmax = 128;
- ymax = 5
- [X, Y] = meshgrid(1:5, 1:128);
- [xi, yi] = meshgrid(.1:.1:5, 0:.5:128);
- zi = griddata(X, Y, data.', xi, yi);
- surf(zi);
Add Comment
Please, Sign In to add comment