Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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);
  5 Kommentare
Walter Roberson
Walter Roberson am 31 Jan. 2021
requiredResolution = 0.5; % in meters
minXin = min(Xin);
maxXin = max(Xin);
Xin1 = minXin + (0:ceil((maxXin - minXin)/requiredResolution))*requiredResolution;
Example: 0.2, 0.8, -> ceil((0.8-0.2)/0.5) -> ceil(0.6/0.5) -> ceil(1.2) -> 2 . Then (0:2)*0.5 -> [0, 0.5, 1.0] + 0.2 -> [0.2, 0.7, 1.2]
Also,
normalVel = griddata(Xin, Yin,avu(:),Xin2,Yin2,'nearest', 'extrap');
Walter Roberson
Walter Roberson am 31 Jan. 2021
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);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Feb. 2021
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);

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by