MATLAB: Error when attempting to plot (“Error using surf (line 71) Z must be a matrix, not a scalar or vector.”)

3d plotsMATLAB and Simulink Student Suitematrix arraysurf

Hello all, could someone please help me debug this error when I attempt to plot ("Error using surf (line 71) Z must be a matrix, not a scalar or vector."), I'm sure it's something very minor that I'm missing as a newbie.
Thanks.
Xpiv = x;
Ypiv = y;
totalu = zeros(size(Xpiv));
for a = 1:length(velocity_magnitude)
totalu(:,a) = totalu(:,a) + velocity_magnitude(:,a);
end
pixelToMetricConversion = 1.26;
fixedPointsM = [137.881, 63.232;124.463, 67.618]; % Teme survey data (gps points)
movingPointsPX = [9.54,3.76;27.42,4.62];
movingPointsM = movingPointsPX./pixelToMetricConversion;
mytform = fitgeotrans(movingPointsM, fixedPointsM, 'nonreflectivesimilarity');
Xin = Xpiv./pixelToMetricConversion;
Yin = Ypiv./pixelToMetricConversion;
[Xin,Yin] = transformPointsForward(mytform, Xin (:), Yin(:) );
requiredResolution = 0.5; % in meters
Xin1 = min(Xin):requiredResolution:max(Xin); % equals 0.5m
Yin1 = min(Yin):requiredResolution:max(Yin);
[Xin2,Yin2] = meshgrid(Xin1,Yin1);
normalVel = griddata(Xin, Yin,avu(:),Xin2,Yin2,'nearest');
figure(3);
hold on;
h3 = surf(Xin2,Yin2,normalVel);

Best Answer

load PIVlabExport_28.01.2021.mat
%% this transforms data from PIVlab into a workable format
Xpiv = x;
Ypiv = y;
avu = velocity_magnitude;
%% this transforms the data into the correct co-ordinate sytem that i am working in
pixelToMetricConversion = 1.26; %difference in distance between metric and pixel...find the distance between the co-ordiantes used in each co-ordinate system, using sqrt as shown below.
% then divde the metric distance by the pixel distance, so 14.11/17.9007 =
% 1.26
% sqrt((9.54-27.42).^2+(3.76-4.62).^2) = 17.9007
% sqrt((137.881-124.463).^2+(63.232-67.618).^2) = 14.1166
fixedPointsM = [137.881, 63.232;124.463, 67.618]; % Teme survey data (gps points)
movingPointsPX = [9.54,3.76;27.42,4.62]; %pixel co-ordinates, or if in PIVlab you have applied a scaling factor (calibration), then it is the PIVlab locations of these points
movingPointsM = movingPointsPX./pixelToMetricConversion;
mytform = fitgeotrans(movingPointsM, fixedPointsM, 'nonreflectivesimilarity');% Reproject the data array so that it is consistent with metric spatial reference used for KLT-IV
Xin = Xpiv./pixelToMetricConversion;
Yin = Ypiv./pixelToMetricConversion;
[Xin,Yin] = transformPointsForward(mytform, Xin (:), Yin(:) );
requiredResolution = 0.5; % in meters
Xin1 = min(Xin):requiredResolution:max(Xin); % equals 0.5m
Yin1 = min(Yin):requiredResolution:max(Yin);
[Xin2,Yin2] = meshgrid(Xin1,Yin1);
normalVel = griddata(Xin, Yin,avu(:),Xin2,Yin2,'nearest');
figure(3);
hold on;
h3 = surf(Xin2,Yin2,normalVel);