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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:58:20+00:00 2026-05-18T09:58:20+00:00

I am new to MATLAB so I don’t even know if this is possible,

  • 0

I am new to MATLAB so I don’t even know if this is possible, but here it is…
I am trying to print multiple lines in a single graph using the plot function. The problem is, I want to be able to specify how many lines the graph should display by simply changing a variable, for example: {This is the pseudo code to what I want to do}

 number_of_lines = 4;
 x = 0:0.5:5;

 function_output[number_of_lines];

 for n=0:number_of_lines
     function_output[n] = sin(n + x);
 end

 for n=0:number_of_lines
     plot(x,function_output[n]);
 end

I know the above pseudo code isn’t exactly MATLAB, but all I want to know if such algorithm is possible to do in MATLAB.

  • 1 1 Answer
  • 3 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-18T09:58:20+00:00Added an answer on May 18, 2026 at 9:58 am

    Here’s one way to implement your example in MATLAB:

    function_output = zeros(numel(x), number_of_lines);  % Initialize a 2-D array
    for n = 1:number_of_lines                   % MATLAB uses 1-based indexing
        function_output(:, n) = sin(n + x).';  %' Compute a row vector, transpose
                                                %   it into a column vector, and
                                                %   place the data in a column of
                                                %   the 2-D array
    end
    plot(x, function_output);  % This will plot one line per column of the array
    

    And here are some documentation links you should read through to learn and understand the above code:

    • Matrices and Arrays
    • Matrix Indexing
    • Arithmetic Operators
    • The plot function
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to matlab, but I know how to do both for loops
I'm new on Matlab. I don't know how to load .txt file end then
I guess this is something from new version of Matlab. But I can't figure
I'm trying to read some matlab code, but I'm new to it. How do
I'm completely new to MATLAB and I want to know what my options are
Hello I am new to MATLAB , I wanted to know how can I
I'm very new to matlab and am more of an ArcGIS user but I'd
Apologies if this is a stupid question, I'm relatively new to Matlab. I've got
I am new to MATLAB and I am trying to built a voice morphing
I am new to MATLAB, and I can't fathom this from the documentation. function

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.