SURF plot: Data dimensions must agree
28 次查看(过去 30 天)
显示 更早的评论
I am trying to plot the magnetic field on a rectangular surface (having x and y coordinates). Hence i have a total of 3 values x,y and B (magnetic field). I have tried plotting the surface plot using normal and transposed datasheet in excel but both of them give me the same data dimensions error. Please help me withi this. I am using the following code till now:
dataset=xlsread('import.xlsx');
x = dataset(:,1);
y = dataset(1,:)
Z = dataset(2:end,2:end)
surf(x,y,Z)
Please see the attached image for clarification.
thank you
0 个评论
采纳的回答
Walter Roberson
2020-5-25
dataset=xlsread('import.xlsx');
x = dataset(2:end,1);
y = dataset(1,2:end);
Z = dataset(2:end,2:end);
surf(x, y, Z.', 'edgecolor', 'none')
3 个评论
更多回答(1 个)
Hélène Parisot-Dupuis
2023-11-28
编辑:Walter Roberson
2023-11-28
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!
3 个评论
Walter Roberson
2023-11-28
There are two competing standards for array notation.
- When using x and y coordinates, western mathematics tends to put the x first (as rows) and then the y (as columns) -- so in terms of standard Cartesian coordinates, horizontal distance first then vertical distance
- When using tables of data, such as a table of costs or a table of trigonmetric values, western mathematics tends to refer to row first and then column -- for example you would look on the row for 1983 and then the column for month -- so vertical distance listed first and then horizontal distance
Any programming language that choses one particular representation (rows mean horizontal distance, rows mean vertical distance) will fail on the other one. So the problem is not a "bug" in MATLAB, or a "mis-design": the problem is competing conventions that cannot both be satisfied.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!