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!