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

조회 수: 7 (최근 30일)
Nihal
Nihal 2024년 6월 18일
편집: Torsten 2024년 6월 18일
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{:}));"

답변 (1개)

Torsten
Torsten 2024년 6월 18일
편집: Torsten 2024년 6월 18일
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
Nihal
Nihal 2024년 6월 18일
Thank you for answering but I got the same error again when I did that.
Torsten
Torsten 2024년 6월 18일
편집: Torsten 2024년 6월 18일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by