Fixing Error in MATLAB 10a for 3D Plotting

  • Context: MATLAB 
  • Thread starter Thread starter adnan jahan
  • Start date Start date
  • Tags Tags
    Error Matlab
Click For Summary
SUMMARY

The discussion addresses a syntax error encountered in MATLAB 10a when attempting to create a 3D plot using complex numbers. The original code, which functions correctly in MATLAB 7, produces an error stating that "X, Y, Z, and C cannot be complex" when executed in MATLAB 10a. The solution provided is to use the real() function to extract the real part of the complex variable before plotting, specifically by modifying the command to mesh(real(u)). This adjustment resolves the issue and allows for successful plotting.

PREREQUISITES
  • Familiarity with MATLAB programming, specifically versions 7 and 10a.
  • Understanding of complex numbers and their representation in MATLAB.
  • Knowledge of 3D plotting functions in MATLAB, particularly the mesh() function.
  • Basic experience with MATLAB syntax and error handling.
NEXT STEPS
  • Explore the differences in handling complex numbers between MATLAB 7 and MATLAB 10a.
  • Learn about the real() function in MATLAB and its applications in data visualization.
  • Investigate other MATLAB plotting functions that may have similar restrictions on complex data.
  • Review MATLAB documentation on error messages related to plotting functions for better troubleshooting skills.
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those transitioning from older versions to MATLAB 10a, as well as data scientists and engineers who work with complex data visualizations in their projects.

adnan jahan
Messages
93
Reaction score
0
Dear Fellows,
I have a program made in MATLAB-7 , about 3D plotting,
simplest form of program is
[x,z]=meshgrid(linspace(0,4),linspace(-1,1));
t=0.1;
b=1.2;
w=-1.0;
k=2+3*i;
M=4+5*i;
u1=k*M;
u=u1.*exp(w*t+i*b*z);

mesh(u)

this works properly in matlab-7
but when I open it in matlab-10a it gives following syntax error
? Error using ==> mesh at 80
X, Y, Z, and C cannot be complex.

Error in ==> abc at 9
mesh(u)

can anyone help me out to get solve this issue?? I don't want to switch back to same old version of matlab,

thanks
 
Physics news on Phys.org
take only the real part:

mesh(real(u))

And compare it to your MATLAB 7 result. It's likely that 7 just automatically takes the real part and doesn't tell you.
 
yessss! thanks Pythagorean for your reply,,

It really works...
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K