Error message from matlab that I do not understand
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I tried to understand the example from the book"computational surface and roundness metrology-chapter 12 page99-100" So i used their codes by typing into matlab to present a clear understanding for me. But there is a part of codes which caused the error message occurring. The codes I used were shown below and the highligheted codes may have some problem this caused the error message when I ran it:Error using + Matrix dimensions must agree. c(j-my,k-mx)=max(max(z1(j-my:j+my,k-mx:k+mx)+b)); Could any one try to have a look and tell me why this error occurring by even using the example codes from the book,please? And how to solve this error? Thank you very much
%3D sinusoidal surface dx=0.001; %spacing in x in mm dy=0.001; nx=128; %number of points along x ny=128; x=(0:1:nx-1)*dx; %generate x array y=(0:1:ny-1)*dy; for j=1:ny for i=1:nx z(j,i)=2*sin(2*pi*x(i)/0.064); end end z=z-mean(mean(z));%shift to 0 mean mesh(x,y,z)
%sphere ball generation radius=0.016; mx=radius/dx;my=radius/dy; j=1; for yr=-radius:dy:radius i=1; for xr=-radius:dx:radius if sqrt(xr^2+yr^2)<=radius b(j,i)=sqrt(radius^2-xr^2-yr^2); else b(j,i)=0; end i=i+1; end end
z1(ny+2*my,nx+2*mx+1)=0; z1(my+1:ny+my,mx+1:nx+mx)=z; for j=my+1:ny+my for k=mx+1:nx+mx c(j-my,k-mx)=max(max(z1(j-my:j+my,k-mx:k+mx)+b)); end end mesh(z); hold on; mesh(c);
1 commentaire
dpb
le 9 Juil 2013
Modifié(e) : Image Analyst
le 10 Juil 2013
Please edit your question to format the code to get rid of the line wrap...impossible to read otherwise.
Mash the 'help' button and follow instructions if it's not clear how to do this. Use the preview window to see your results and keep at it until they're clearly formatted w/ line-wrapping code. http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Réponses (1)
Tom Lane
le 9 Juil 2013
I see j=1 in your code but I don't see j incremented after that. I suspect you intended to change j somewhere.
Here's a hint. Since this is a script, you can inspect the workspace variables after the error. When I do that I see you trying to add these two things of different sizes:
>> size(z1(j-my:j+my,k-mx:k+mx))
ans =
33 33
>> size(b)
ans =
1 33
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!