Help with this MATLAB GUI code
Mostrar comentarios más antiguos
I'm writing a code for a GUI program and there's something I can't get around.
M = str2double(get(handles.Input_M,'String'));
n = str2double(get(handles.Input_n,'String'));
Vx = str2double(get(handles.Input_Vx,'String'));
Dx = str2double(get(handles.Input_Dx,'String'));
Dy = str2double(get(handles.Input_Dy,'String'));
Dz = str2double(get(handles.Input_Dz,'String'));
t = str2double(get(handles.Input_3D_t,'String'));
X = str2double(get(handles.Input_3D_x,'String')); %%%error
Y = str2double(get(handles.Input_3D_y,'String')); %%%error
Z = str2double(get(handles.Input_3D_z,'String'));
[X,Y] = meshgrid(-10:0.1:10);
C = ((M./n)./(8).*((3.14.*t).^1.5).*sqrt(Dx.*Dy.*Dz)).*exp((-((X-Vx.*t).^2)./4.*Dx.*t)-(Y.^2/4.*Dy.*t)-(Z.^2./4.*Dz.*t)); %%%equation
contour3(X,Y,C,100)
I let the user input the variables for the equation which will generate a 3D contour. However for X and Y i get the red squiggly line that says "The value assigned to variable X might be unused".
So when I test the program, each different variable would change the contour in someway, however no matter what value I put for X or Y the contour doesn't change! Any ideas?
Respuestas (3)
Grzegorz Knor
el 26 de Sept. de 2011
In this line:
[X,Y] = meshgrid(-10:0.1:10);
You overwrite X and Y.
9 comentarios
Bastion
el 26 de Sept. de 2011
Grzegorz Knor
el 26 de Sept. de 2011
You load the variables X and Y from handles structure:
X = str2double(get(handles.Input_3D_x,'String')); %%%error
Y = str2double(get(handles.Input_3D_y,'String')); %%%error
And then, a few lines below, you overwrite them by:
[X,Y] = meshgrid(-10:0.1:10);
So regardless of the contents of the fields handles.Input_3D_y and handles.Input_3D_x, variables X & Y will not change.
Bastion
el 26 de Sept. de 2011
Grzegorz Knor
el 26 de Sept. de 2011
I don't see the code, therefore I can only guess what the variables X and Y mean.
Could you explain it:
X = str2double(get(handles.Input_3D_x,'String'));
Y = str2double(get(handles.Input_3D_y,'String'));
?
Jan
el 26 de Sept. de 2011
@Bastian: The solution is trivial: You have to rename einer the first or the second definition of X and Y.
If you write "X=3; X=4" the first definition is overwritten and MLint warns for that (so this is *not* an error! It is only mostlikely not wanted).
Bastion
el 27 de Sept. de 2011
Bastion
el 27 de Sept. de 2011
Grzegorz Knor
el 27 de Sept. de 2011
If X and Y will be a scalar values, then C also will be a scalar, and you will not be able to draw a contour plot.
Bastion
el 27 de Sept. de 2011
Jan
el 27 de Sept. de 2011
After your comment to Grzegorz's answer:
I'm deeply confused about your question, how you could do this. The problem is, that you overwrite an existing definition equivalent to:
X = 3;
X = 4;
You can avoid this by renaming on of the variables, e.g.:
X1 = 3;
X = 4;
Or:
X = 3;
X2 = 4;
But this is trivial and the program you've posted looks like you have enough programming skills to find this by your own.
The user can "input any number" for X and Y, so let's assume it is 19 in both cases. Now, how do you want this number to be used "as axis"? Currently you overwrite the values by "[X,Y] = meshgrid(-10:0.1:10);". Perhaps you want something like:
X = linspace(-X, X, 100);
Or:
X = -X:0.1:X
1 comentario
Bastion
el 27 de Sept. de 2011
Bastion
el 5 de Oct. de 2011
0 votos
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!