Filter löschen
Filter löschen

Error using surf (line 71) Z must be a matrix, not a scalar or vector.

4 Ansichten (letzte 30 Tage)
Nihal
Nihal am 18 Jun. 2024
Bearbeitet: Torsten am 18 Jun. 2024
I got this error when i write this code;
file_nc = 'data.nc';
% see the description of the nc file using ncdisp
% example: ncdisp(file_nc)
% store the information in a struct
info_nc = ncinfo(file_nc);
sn = ncread(file_nc, 'south_north');
we = ncread(file_nc, 'west_east');
height_ws = ncread(file_nc, 'height');
ws = ncread(file_nc, 'wind_speed_mean');
[we_m , sn_m] = meshgrid(we,sn);
for i=1:length(height_ws)
figure
surf(we_m, sn_m, squeeze(ws(:,:,i))','EdgeColor', 'none')
title(strcat("Wind speed at ", num2str(height_ws(i)), " m"))
view(2)
c1 = colorbar;
c1.Title.String = 'U_{avg} [m/s]';
xlabel('Projected West-East [m]')
ylabel('Projected South-North [m]')
axis equal
axis tight
end
Error using surf (line 71)
Z must be a matrix, not a scalar or vector. The line 71 is "error(surfchk(dataargs{:}));"

Antworten (1)

Torsten
Torsten am 18 Jun. 2024
Bearbeitet: Torsten am 18 Jun. 2024
Before your loop insert the commands
size(squeeze(ws(:,:,1))')
size(we_m)
size(sn_m)
For surf to work, all sizes must be the same.
  2 Kommentare
Nihal
Nihal am 18 Jun. 2024
Thank you for answering but I got the same error again when I did that.
Torsten
Torsten am 18 Jun. 2024
Bearbeitet: Torsten am 18 Jun. 2024
I told you that the output to the command window for these three values must be equal in order for "surf" to work without error. I did not claim that it solves your problem.
According to what three values you get, you will have to change your code. We cannot help you further because we don't know the content of your data file.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by