Error using surf (line 71) Z must be a matrix, not a scalar or vector.
7 次查看(过去 30 天)
显示 更早的评论
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{:}));"
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!