Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:12:26+00:00 2026-05-26T18:12:26+00:00

I am trying to draw the figure of a 3D polar plot by converting

  • 0

I am trying to draw the figure of a 3D polar plot by converting it from polar to cartesian coordinates and using surf() to plot it.

Problem: I get the error ??? CData must be an M-by-N matrix or M-by-N-by-3 array. Where did I go wrong? I am quite new to MATLAB and do not understand what is happening.

MATLAB Code

clear all;
close all;

N=50;
%define matrices for ploting
x=zeros(N,N,N);
y=zeros(N,N,N);
z=zeros(N,N,N);
f=zeros(N,N,N);

%define basic input variables
r=linspace(0,2,N);
theta=linspace(0,pi,N);
phi=linspace(0,2.*pi,N);

for ii=(1:N) %use ii, jj to avoid confusion with the imaginary units
    for jj=(1:N)
        for kk=(1:N)
            x(ii,jj,kk)=r(ii).*sin(theta(jj)).*cos(phi(kk)); %%not using 
            %%for loop probably can work too, test later
            y(ii,jj,kk)=r(ii).*sin(theta(jj)).*sin(phi(kk));

            z(ii,jj,kk)=r(ii).*cos(theta(jj));

            f(ii,jj,kk)=r(ii).*exp(-r(ii)).*cos(theta(jj));
        end
    end
end

figure;
surf(x,y,z,f);
colormap([1,1,1]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:12:27+00:00Added an answer on May 26, 2026 at 6:12 pm

    surf plots a surface: so each (x,y) point has a height, z.

    E.g.

    N=50;
    [X Y] = meshgrid(linspace(0,2,N));
    Z = zeros(size(X));
    
    for ii=(1:N)
        for jj=(1:N)
            x = X(ii,jj);
            y = Y(ii,jj);
            [theta, r] = cart2pol(x,y);
             Z(ii,jj) =r * exp(-r) * cos(theta);
        end
    end
    
    figure;
    surf(X,Y,Z);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using CALayers to draw to a UITableViewCell. I'm trying to figure out how
I am trying to draw in a web worker using html5 canvas. The worker
I'm trying to draw an open rectangle using a Polygon: int[] xPoints = {1,1,3,3};
I'm trying to figure out how to draw graphics in XNA, and someone else
I'm trying to figure out how the books draw a box perhaps with different
I'm trying to make OpenGL draw the figure that I'm loading with OPENFILENAME .
I'm trying to figure out how I can use Canvas to draw a small
I'm trying to figure out a way to draw several images which are pulled
I'm trying to figure out how to do texture mapping using GLSL version 4.10.
I am trying to draw a box in a console but I cant figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.