Best way to plot a surface whose matrix has values of +/- infinity

3 visualizaciones (últimos 30 días)

Hi there! What is the best way to plot a 3D surface whose matrix C = A ./ B contains values of +/- infinity (whenever entries in B are zero)? Currently I am using surf( ), which results in weird vertical cross sections. I looked into the fillMissing( ) and scatteredInterpolant( ) functions. Is there a best / recommended way to proceed, to plot a smooth surface? Thanks in advance,

  2 comentarios
Torsten
Torsten el 7 de En. de 2025
Editada: Torsten el 7 de En. de 2025
Do you mean C = A/B or C = A./B ?

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 7 de En. de 2025
Without the actual matrices (or representative matrices), it is diifficult to determine what is best.
Note that fillmissing will only interpolate NaN values, not ±Inf since those aren’t actually ‘missing’. If you want to fill the ±Inf values to a specific value or simply interpolate them, first change the ±Inf values to NaN, and then use fillmissing with the appropriatee options, depending on what you want to fill the values with.
C = rand(10);
C(randi(numel(C),5,1)) = Inf;
disp(C)
0.9588 0.5339 0.0804 0.2514 0.9898 0.6714 0.1631 0.9184 0.4323 0.1071 0.1392 Inf 0.7912 0.7563 0.1575 0.9422 0.5456 0.6430 Inf 0.7044 0.3319 0.2681 0.3178 0.2085 0.2741 0.3512 0.3111 0.8425 0.3927 0.8152 Inf 0.6310 0.1859 Inf 0.8198 0.6044 0.2868 0.6497 0.2099 0.6087 0.4576 0.6661 0.5924 0.4996 0.2698 0.0185 0.2673 0.7120 0.4400 0.4482 0.9765 0.9727 0.3978 0.5604 0.9376 0.0350 0.3679 0.4305 0.6991 0.0103 0.9861 0.9224 0.5639 0.3243 0.6420 0.0775 0.5452 0.5099 0.2087 0.8130 0.2795 0.8829 0.9604 0.6973 0.7640 0.9333 0.2153 0.5529 0.6946 0.6082 0.9332 Inf 0.2878 0.9074 0.2452 0.4789 0.6202 0.8002 0.1871 0.7009 0.1150 0.5625 0.2731 0.5491 0.8665 0.0998 0.9425 0.4497 0.5860 0.4568
C(~isfinite(C)) = NaN
C = 10×10
0.9588 0.5339 0.0804 0.2514 0.9898 0.6714 0.1631 0.9184 0.4323 0.1071 0.1392 NaN 0.7912 0.7563 0.1575 0.9422 0.5456 0.6430 NaN 0.7044 0.3319 0.2681 0.3178 0.2085 0.2741 0.3512 0.3111 0.8425 0.3927 0.8152 NaN 0.6310 0.1859 NaN 0.8198 0.6044 0.2868 0.6497 0.2099 0.6087 0.4576 0.6661 0.5924 0.4996 0.2698 0.0185 0.2673 0.7120 0.4400 0.4482 0.9765 0.9727 0.3978 0.5604 0.9376 0.0350 0.3679 0.4305 0.6991 0.0103 0.9861 0.9224 0.5639 0.3243 0.6420 0.0775 0.5452 0.5099 0.2087 0.8130 0.2795 0.8829 0.9604 0.6973 0.7640 0.9333 0.2153 0.5529 0.6946 0.6082 0.9332 NaN 0.2878 0.9074 0.2452 0.4789 0.6202 0.8002 0.1871 0.7009 0.1150 0.5625 0.2731 0.5491 0.8665 0.0998 0.9425 0.4497 0.5860 0.4568
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
C = fillmissing(C, 'linear')
C = 10×10
0.9588 0.5339 0.0804 0.2514 0.9898 0.6714 0.1631 0.9184 0.4323 0.1071 0.1392 0.4010 0.7912 0.7563 0.1575 0.9422 0.5456 0.6430 0.4125 0.7044 0.3319 0.2681 0.3178 0.2085 0.2741 0.3512 0.3111 0.8425 0.3927 0.8152 0.3948 0.6310 0.1859 0.3540 0.8198 0.6044 0.2868 0.6497 0.2099 0.6087 0.4576 0.6661 0.5924 0.4996 0.2698 0.0185 0.2673 0.7120 0.4400 0.4482 0.9765 0.9727 0.3978 0.5604 0.9376 0.0350 0.3679 0.4305 0.6991 0.0103 0.9861 0.9224 0.5639 0.3243 0.6420 0.0775 0.5452 0.5099 0.2087 0.8130 0.2795 0.8829 0.9604 0.6973 0.7640 0.9333 0.2153 0.5529 0.6946 0.6082 0.9332 0.7227 0.2878 0.9074 0.2452 0.4789 0.6202 0.8002 0.1871 0.7009 0.1150 0.5625 0.2731 0.5491 0.8665 0.0998 0.9425 0.4497 0.5860 0.4568
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Another option is to do someething similar with ‘B’ except to change the zero values to NaN and then use fillmissinng to interpolate them. Then do the division.
.
  23 comentarios
Noob
Noob el 8 de En. de 2025
Hi Star Strider! Ok, got it; ultimately, I don't have the final say in such things. I can only propose ideas, and keep working, and moving forward. This particular figure and its associated model is undoubtedly difficult to understand. I want to comment on your answer about color shading, so I'll go there now -- thanks again!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by