fixed points in the plots

Hi,
I have a program that includes a graph of functions in 3D
I need to fix points on the drawing (show the location of the points on the drawing),
I used
hold on ;
plot (A(1),B(2.1),G(3.021),'r*')
plot (A(0.0001),B(3),G(3.21),'r*')
plot (A(3.654),B(3.1),G(2.15),'r*')
But an error appeared to me...
Error in POINTS (line 45)
plot (A(1),B(2.1),G(3.021),'r*')
if any Prof. can help me ...thanks alot

 采纳的回答

syms A B G
A, B, and G are created as scalar symbols
f = matlabFunction(sum1m2, 'vars', [A, B, G]);
g = matlabFunction(sum3m4, 'vars', [A, B, G]);
h = matlabFunction(sum5m6, 'vars', [A, B, G]);
f, g, and h are created as numeric functions of three inputs.
plot (A(1),B(2.1),G(3.021),'r*')
plot (A(0.0001),B(3),G(3.21),'r*')
plot (A(3.654),B(3.1),G(2.15),'r*')
You try to index scalar A at 1, which works, giving you back the scalar symbol A .
You try to index scalar B at 2.1, which fails, because you cannot index at non-integers... and if you could do that, you would be indexing past the end of the scalar.
You try to index scalar G at 3.021, which fails, non integer, past the end of the scalar. Is it possible that function g was intended? But function g needs three parameters, not one.
I suspect what you want is
plot ((1),(2.1),(3.021),'r*')
plot ((0.0001),(3),(3.21),'r*')
plot ((3.654),(3.1),(2.15),'r*')

10 个评论

Thanks Prof. Walter for the valuable answer... yes I want these points..I write it but also not appear in the graph
I write the points as integer, but also not appear in the graph..
is imposible fixed points in graph in matlab???
It works for me. If I take your code and remove the
plot (A(1),B(2.1),G(3.021),'r*')
plot (A(0.0001),B(3),G(3.21),'r*')
plot (A(3.654),B(3.1),G(2.15),'r*')
which we already know to be wrong, and if we put in
plot3(1,2,3,'r*')
then you can see a red star in the graph.
You have "hold on" in effect, and your xlim, ylim, and zlim are all [0 4], so if you were to try to draw at points outside that range, then they would not be in view. For example if you wanted to plot at 4.1 3.1 2.1 then it would be off the screen. If that happens you can use
xlim auto; ylim auto; zlim auto
hasan s
hasan s 2021-4-17
编辑:hasan s 2021-4-17
realy appear in your matlab ... why not appear in my matlab ???
please where you put
plot ((1),(2.1),(3.021),'r*')
plot ((0.0001),(3),(3.21),'r*')
plot ((3.654),(3.1),(2.15),'r*')
I put it in the end of program , and I take the same file in the interval [0,4].please , if you can ..attach the file that appear the 3 points
I try
plot3(1,2,3,'r*')
and appear * without graph of functions
NumPoints = 50;
tic
digits(16);
syms A B G
N = 100;
Q1 = rand(10,N);
Q = vpa(reshape(Q1,1,[]));
sum1=0;sum2=0;sum3=0;sum4=0;sum5=0;sum6=0;
for j=1:1000
sum1=sum1+1/(A+(G*B*((Q(j))^(G-1))));
sum2=sum2+(Q(j));
sum3=sum3+(G*((Q(j))^(G-1)))/(A+(G*B*((Q(j))^(G-1))));
sum4=sum4+(Q(j))^(G);
sum5=sum5+(((G*log(Q(j)))*((Q(j))^(G-1)))+((Q(j))^(G-1)))/(A+(B*G*((Q(j))^(G-1))));
sum6=sum6+((Q(j))^(G))*log(Q(j));
end
sum1m2 = vpa(sum1 - sum2);
sum3m4 = vpa(sum3 - sum4);
sum5m6 = vpa(B*sum5-B*sum6);
f = matlabFunction(sum1m2, 'vars', [A, B, G]);
g = matlabFunction(sum3m4, 'vars', [A, B, G]);
h = matlabFunction(sum5m6, 'vars', [A, B, G]);
[Ag, Bg, Gg] = meshgrid(linspace(0, 4,NumPoints));
Fgrid = f(Ag,Bg,Gg);
Ggrid = g(Ag,Bg,Gg);
Hgrid = h(Ag,Bg,Gg);
grids = {Fgrid, Ggrid, Hgrid};
gridnames = {'f', 'g', 'h'};
ngrid = length(grids);
cmap = parula(ngrid);
view(3);
patches = gobjects(1,ngrid);
surfaces = cell(ngrid, 1);
for K = 1 : ngrid
surfaces{K} = isosurface(Ag, Bg, Gg, grids{K}, 0);
patches(K) = patch(surfaces{K}, 'facecolor', cmap(K,:), 'edgecolor','none','FaceAlpha', 0.5, 'displayname', gridnames{K});
end
xlabel('A');
ylabel('B');
zlabel('G');
legend show
hold on ;
plot3((1),(2.1),(3.021),'r*')
plot3((0.0001),(3),(3.21),'r*')
plot3((3.654),(3.1),(2.15),'r*')
hold off
toc
Now the points appear ...
Thank you very very much prof. Walter
please ...Why did the point name not appear with * , as
A 1
B 2.1
G 3.021
You did not ask for that.
points = [
1, 2.1, 3.021;
0.0001, 3, 3.21;
3.654, 3.1, 2.15;
]
scatter3(points(:,1), points(:,2), points(:,3), 'r*');
for K = 1 : size(points,1)
text(points(K,1), points(K,2), points(K,3), sprintf('A=%g B=%g G=%g', points(K,:)));
end
Sorry, I thought it appears without other commands...
thank you very very much Prof. Walter
There are also datatips(), but datatips() automatically move to the closest data point, which I did not think you would want to do.
Thanks prof. Walter for this valuable information ... Yes, right now, I just need to hold the points

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by