Unexpected flat surface with surf command

I have two parallel lines in a 3D space. I use the following code to create a curved surface which goes though all lines:
% Iterate through the cells in data_cell
for i = 1:2
% Extract the current 500x2 array
current_data = data_cell{i};
% Append the first column values to x
x(:, i) = current_data(:, 1);
% Append the second column values to z
z(:, i) = current_data(:, 2);
% Calculate the index for Dp_values using modular arithmetic
dp_index = mod(i - 1, length(Dp_values)) + 1;
% Create a vector of propeller sizes for this data cell
propeller_size = Dp_values(dp_index) * ones(size(current_data, 1), 1);
y(:, i) = propeller_size;
end
[X, Y] = meshgrid(x, Dp_values);
Z = griddata(x, y, z, X, Y, 'cubic');
surf(X, Y, Z);
However, the final result shows a flat surface on top of the curved surface. The figure looks like this:
I am not sure what goes wrong here, and I have tried to make x, y, z as vectors but it still gave me the same result.
I appreciate any help. Thanks.
For the reference, the data in x is like
[0.0800000000000000 0.0800000000000000
0.0818000000000000 0.0818000000000000
0.0837000000000000 0.0837000000000000
...
0.998200000000000 0.998200000000000
1 1 ]
and y is like
[0.300000000000000 0.470000000000000
0.300000000000000 0.470000000000000
0.300000000000000 0.470000000000000
...
0.300000000000000 0.470000000000000]
and z is like
[0.545136000000000 0.282617000000000
0.541518000000000 0.281099000000000
0.537900000000000 0.279581000000000
...
0.165439000000000 0.0849740000000000]

Respuestas (1)

Star Strider
Star Strider el 30 de Sept. de 2023

0 votos

I do not completely understand the problem, however:
[X, Y] = meshgrid(sort(x), sort(Dp_values));
could solve the problem.
The griddata, scatteredInterpolant, and other such functions will likely not care if the data are sorted or not, so long as the argument dimensions make sense to the functions. (If all goes according to plan, sorting the initial vectors should produce the desired surf plot)

4 comentarios

Yi-Kai Peng
Yi-Kai Peng el 30 de Sept. de 2023
Hi Star,
Thank you for your answer. The problem in this plot is that surf function gives me a flat surface as well (The blue area). However, I only want to curved surface, which is the lower part.
Star Strider
Star Strider el 30 de Sept. de 2023
I understand that.
I do not have your data, so I can only suggest a solution, based on my experience.
Did you experiment with sorting the vectors as I described in my Answer? If so, what was the result? If that did not solve the problem, I will need your data and code, and preferably a short description of what the data are and the problem you want to solve with them, to experiment with.
Yi-Kai Peng
Yi-Kai Peng el 30 de Sept. de 2023
Hello Star,
Surprisingly I solved the problem by transposing all x, y, z data.
However, even I use cubic in griddata function, the surface still looks like linear interpolation. Do you have suggestion to solve this problem?
Star Strider
Star Strider el 30 de Sept. de 2023
Transposing the matrices obviously worked.
Experiment with the scatteredInterpolant function (instead of griddata) to see if it gives a better result. The values may not be defined between the red lines, so a linear interpolation may be the only option, regardless of the chosen interpolation method.
I do not have your data, so this is the best I can do.

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Sept. de 2023

Comentada:

el 30 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by