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 912939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:28:10+00:00 2026-05-15T17:28:10+00:00

I wonder why these two code doesn’t produce the same plot? code 1: x=[2,5,7];

  • 0

I wonder why these two code doesn’t produce the same plot?

code 1:

x=[2,5,7];
y=[10,4,3];
plot(x,y);

code 2:

x=[2,5,7];
y=[10,4,3];

for i=1:length(x)
    xx=x(i);
    yy=y(i);
    plot(xx,yy);

end

EDITED:
How I can make the output of Code 2 similar to output in Code 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-15T17:28:11+00:00Added an answer on May 15, 2026 at 5:28 pm

    Code 1

    You’re drawing a line with the x and y coordinates defined in the vectors with the plot(x,y) command. By default, it means plot(x,y,'-'); which means you draw a line (-).

    Code 2

    You’re drawing individual points (no line) stored in the vectors since you’re calling plot for each point (xx,yy)

    You can duplicate the effect in Code 2 in Code 1, with the following change:

    plot(x,y,'.');
    

    This forces MATLAB to only plot the points and not the connecting line

    If you want the points and the line,

    plot(x,y,'-.');
    

    For more details, check out the documentation of the plot command.

    Sample Code:

    %# If you know the number of elements, preallocate
    %# else just initialize xx = []; and yy =[];
    xx = zeros(100,1);
    yy = zeros(100,1);
    
    %# Get the data
    for i = 1:length(xx)
        xx(i) = getXSomehow();
        yy(i) = getYSomehow();
    end
    
    %# Plot the data
    plot(xx,yy);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder what these two words mean. I encountered them in Doctrine's documentation ,
I wonder if anyone knows why the following two pieces of code behave very
I wonder if you can help me. I am using the below code and
I wonder if there is a way of concating two strings in Silverlight inside
I just wonder whether there will be any conflict if two service intents are
I wonder if these words are synonymous with each other?
I wonder how apps like these generate screenshots for different browsers. Are they using
This is probably two questions in one.... Firstly i wonder how does android run
Wonder if anyone can help. I recently had an issue with UTF8 in the
Looking at this related SO question , I can't help but wonder about the

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.