I have a 3D matrix containing values of potential between two charges for every x,y and z value so that I can find out the potential at any point by inputting three coordinates. The problem I'm having is I am unable to plot a 3D surface plot showing the potential.
I try and use surf() but the error says the value must be scalar, vector or numerical. I do have 2 inf values where the two charges lie, is this whats causing the problem and if so how do I get around it?

6 comentarios

madhan ravi
madhan ravi el 6 de Nov. de 2018
Editada: madhan ravi el 6 de Nov. de 2018
upload your datas by attaching the data file
James
James el 6 de Nov. de 2018
This is all the data.
Jan
Jan el 6 de Nov. de 2018
Please post the code and a copy of the complete error message.
James
James el 9 de Nov. de 2018
[X3,Y3] = meshgrid((-4.5:0.1:4.5),(-4.5:0.1:4.5)); d = (Vexact2 - Vapprox);
where d is a 91x91x81 matrix, containing all values of potential across a meshgrid of:
[X,Y,Z] = meshgrid((-4.5:0.1:4.5),(-4.5:0.1:4.5),(-4:0.1:4)).
I am trying to plot each value of the potential against corresponding X and Y (X3,Y3) in the plane z=0. I have tried using
surf(X3,Y3,d)
But get an error as this doesnt work at all, and another error saying data dimensions dont agree.
Jan
Jan el 9 de Nov. de 2018
If you mention, that you get an error, please post a copy of the complete message. It is not possible that there is "another error", because Matlab stops at the first error already. "saying data dimensions dont agree" is less useful than a copy of the message, because then the readers do not have to guess in which line the error occurs.
Please post the relevant part of the code and a copy of the error message.
James
James el 9 de Nov. de 2018
Error using surf (line 71) Data dimensions must agree.
Error in coursw (line 84) surf(X3,Y3,d)

Iniciar sesión para comentar.

 Respuesta aceptada

madhan ravi
madhan ravi el 9 de Nov. de 2018
Editada: madhan ravi el 9 de Nov. de 2018

0 votos

load matlab.mat
[X3,Y3] = meshgrid((-4.5:0.1:4.5),(-4.5:0.1:4.5));
for i = 1:81
figure()
surf(X3,Y3,d(:,:,i)) %likewise 1 to 81
end

4 comentarios

James
James el 9 de Nov. de 2018
Thanks for replying, this code does produce a graph however it produces 82 figures, each varying slightly from each other. Why does this happen?
madhan ravi
madhan ravi el 9 de Nov. de 2018
The graph varies because the data’s are different but I don’t understand why 82 figures . Does 82 figures produce plot or only 81?
James
James el 9 de Nov. de 2018
It produces 81 plots of what it should look like, but each of them change the surface shape very slightly.
madhan ravi
madhan ravi el 9 de Nov. de 2018
So there’s nothing wrong in it James because the data points vary in each page of d that’s why there is slight change nothing to worry about it

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 6 de Nov. de 2018

Comentada:

el 9 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by