Guest User

Untitled

a guest
Jan 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. [ 1 1 1 1 2 4 8 2 1 1 1 1 2 1 1 2 ]
  2. [ 1 . 1 . 3 . 6 . 1 . 1 . 2 . 1 . ]
  3. [ 1 . . . 3 . . . 1 . . . 2 . . . ]
  4. [ 1 . . . . . . . 1 . . . . . . . ]
  5.  
  6. % initialize the matrix of sampled data
  7. indx = 1;
  8. data = NaN(5, 128);
  9. for row=1:5
  10. for col=1:128
  11. if ( mod(col-1, indx) == 0)
  12. data(row, col) = rand();
  13. end
  14. end
  15. indx = power(2, row);
  16. end
  17.  
  18. % Linearize the data in each row to overcome NaN entries
  19. for row=1:5
  20. fprintf('Linear interpolation for row %dn', row);
  21. indx = NaN;
  22. for col=1:128
  23. if (data(row, col) ~= NaN) || (col == 128)
  24. if isnan(indx)
  25. % initalize first point
  26. indx = col;
  27. elseif isnan(data(row,col)) && (col ~= 128)
  28. % ignore NaN values between 1 and N-1
  29. elseif ((col-1) ~= indx)
  30. fprintf('Creating linspace from col=%d to indx=%dn', col, indx)
  31. if (col == 128)
  32. % first row will always contain all points
  33. v = linspace(data(row, indx), data(1, col), col+1-indx);
  34. else
  35. v = linspace(data(row, indx), data(row, col), col+1-indx);
  36. end
  37. i=1;
  38. for j=indx:col
  39. data(row,j) = v(i); % update our data
  40. i = i + 1; % increment counter
  41. end
  42. indx = col;
  43. elseif ((col-1) == indx)
  44. indx = NaN;
  45. end
  46. end
  47. end
  48. end
  49.  
  50. % Populate the X and Y vectors, X is columns, Y is rows, Z is data
  51. xmin = 1;
  52. ymin = 1;
  53. xmax = 128;
  54. ymax = 5
  55. [X, Y] = meshgrid(1:5, 1:128);
  56.  
  57. [xi, yi] = meshgrid(.1:.1:5, 0:.5:128);
  58. zi = griddata(X, Y, data.', xi, yi);
  59. surf(zi);
Add Comment
Please, Sign In to add comment