Error using surf (line 71) Data dimensions must agree
Mostrar comentarios más antiguos
Hello,
I have the kind of problem with my code and I don't understand why:
for it=1:2
xt(it,1)=it
for jt=1:3
yt(1,jt)=jt
zt(it,jt)=it+(jt-1)
end
end
figure;
surf(xt,yt,zt,'EdgeColor', 'None', 'facecolor', 'interp');
view(2);
colormap(jet(256));
c = colorbar;
Could you help me to find my error please?
Thanks in advance!
1 comentario
Walter Roberson
el 28 de Nov. de 2023
Also answered (with clarifications about the problem) at https://www.mathworks.com/matlabcentral/answers/532468-surf-plot-data-dimensions-must-agree#comment_2978992
Respuestas (1)
More like this?
for it=1:2
for jt=1:3
zt(it,jt)=it+(jt-1);
end
end
[x,y] = meshgrid(1:3,1:2);
figure;
surf(x,y,zt,'EdgeColor', 'None', 'facecolor', 'interp');
view(2);
colormap(jet(256));
c = colorbar;
4 comentarios
Hélène Parisot-Dupuis
el 28 de Nov. de 2023
@Hélène Parisot-Dupuis: xt and yt don't have to be matrices. If they are vectors, then zt must be of size numel(yt)-by-numel(xt). Your zt is of size numel(xt)-by-numel(yt), so if you transpose zt in the surf call, it runs without error.
for it=1:2
xt(it,1)=it;
for jt=1:3
yt(1,jt)=jt;
zt(it,jt)=it+(jt-1);
end
end
xt
yt
zt
figure;
surf(xt,yt,zt.','EdgeColor', 'None', 'facecolor', 'interp');
view(2);
colormap(jet(256));
c = colorbar;
Hélène Parisot-Dupuis
el 28 de Nov. de 2023
Voss
el 28 de Nov. de 2023
You're welcome!
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

