why surface plot is connecting its edges?

I need to create a 4d plot and am using the surf plot with the colors being the 4th dimension of the graph, however, for some data sets the edges of the surface is connecting together as can be seen in the first image, the second image uses the same script but it does not connect the edges. Any help will be very appreciated.

5 件のコメント

Walter Roberson
Walter Roberson 2021 年 1 月 9 日
Your Current data appears to loop back to the beginning.
Wilson Duarte
Wilson Duarte 2021 年 1 月 10 日
Unfortunately not. I attached the data I am using for the graph and the code to generate the plot is below.
x is in the first column, y in the second and v in the third.
[xq, yq] = meshgrid(x, y);
vq = griddata(x, y, v, xq, yq);
surf(x, y, vq, 'FaceColor', 'b')
Image Analyst
Image Analyst 2021 年 1 月 10 日
I don't think that is your whole program. For example there is nothing there that created the legend or labeled the axes. So some code is missing. Please post your whole program.
Walter Roberson
Walter Roberson 2021 年 1 月 10 日
Your x does recycle
T = readtable('data_surf.xlsx');
T.Properties.VariableNames = {'x', 'y', 'v'};
plot(T.x)
minx = min(T.x);
maxx = max(T.x);
miny = min(T.y);
maxy = max(T.y);
xvec = linspace(minx, maxx);
yvec = linspace(miny, maxy);
[X,Y] = ndgrid(xvec, yvec);
F = scatteredInterpolant(T.x, T.y, T.v);
V = F(X,Y);
surf(X, Y, V, 'edgecolor', 'none')
Wilson Duarte
Wilson Duarte 2021 年 1 月 10 日
編集済み: Wilson Duarte 2021 年 1 月 10 日
all the variables recycle because for each temperature I have 9 values of x (SOC) and for each value of SOC I have 15 values of y (current)
your solution does work for the graph but I cannot use it since the grid shows the position of the each parameter and I need this as well
thank you anyways

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2021 年 1 月 10 日

0 投票

Try this for the file provided, and the others that likely have similar formats.
Note — It is only necessary to reshape the matrix, and that griddata (as much as I like the function) is not necessary here.
The Code —
D = readmatrix('data_surf.xlsx');
[U2,ix] = unique(D(:,2)); % Determine Initial Indices Of Repeated Elements
ixd = diff(ix); % Lenmgth Of Repeated Elements
Dr = reshape(D,mean(ixd),[]); % Reshape Data Matrix
collen = size(Dr,2)/size(D,2); % Column Block Lengths
for k = 1:size(D,2)
M{k} = Dr(:,(1:collen)+(k-1)*collen); % Segment By Column Blocks
end
figure
surf(M{1}, M{2}, M{3})
grid on
xlabel('Current')
ylabel('SOC')
zlabel('Parameter')
The Plot —
.

2 件のコメント

Wilson Duarte
Wilson Duarte 2021 年 1 月 10 日
it works, thank you a lot
Star Strider
Star Strider 2021 年 1 月 10 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by