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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:27:43+00:00 2026-06-09T14:27:43+00:00

Is there a way to pass in N datasets and plot them in a

  • 0

Is there a way to pass in N datasets and plot them in a line graph using for loop?
I did it by passing fixed number of parameter ( eg M1, M2, M3, M4), and repeat plotting manually like below. But I wonder if there are way to code the function dynamically? Let say I can pass in 4 datasets, or 40 datasets, and plot them in one graph via looping.

function plot_four_cdf(M1,M2,M3,M4)

[ycdf1,xcdf1] = cdfcalc(M1);
ycdf1 = ycdf1(2:length(ycdf1));
plot(xcdf1, ycdf1, '-+k', 'LineWidth', 1);

hold on;
[ycdf2,xcdf2] = cdfcalc(M2);
ycdf2 = ycdf2(2:length(ycdf2));
plot(xcdf2, ycdf2, '-ok', 'LineWidth', 1);
hold off;

hold on;
[ycdf3,xcdf3] = cdfcalc(M3);
ycdf3 = ycdf3(2:length(ycdf3));
plot(xcdf3, ycdf3, '-*k', 'LineWidth', 1);
hold off;

hold on;
[ycdf4,xcdf4] = cdfcalc(M4);
ycdf4 = ycdf4(2:length(ycdf4));
plot(xcdf4, ycdf4, '-sk', 'LineWidth', 1);

legend('M100','M80','M50','M20',...
   'Location','SE')

xlabel('Relative Error');
ylabel('CDF');
end
  • 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-06-09T14:27:45+00:00Added an answer on June 9, 2026 at 2:27 pm

    You can group all your data in a cell-array and pass that to the function:

    function plot_cdfs(M)
    
        figure, hold on
    
        linestyles = {...
            '-+k', '-ok', '-*k', '-sk', ...
            '-+r', '-or', '-*r', '-sr');
    
        legendentries = cell(size(M));
    
        for ii = 1:numel(M)
            [ycdf, xcdf] = cdfcalc(M{ii});
            plot(xcdf, ycdf(2:end), linestyles{ii}, 'LineWidth', 1);
            legendentries{ii} = ['M' num2str(ii)];    
        end
    
        legend(legendentries{:}, 'Location','SE')
    
        xlabel('Relative Error');
        ylabel('CDF');
    
    end
    

    Note that M is constructed something like

    M = {M1, M2, M3, ...} 
    

    possibly also in a loop of its own. Note also that the legendentries are now kind of hard to define. You can pass them as a separate argument to the function (better option), or stuff them in the same cell array M next to the data they describe (not very portable).

    Note also that you’d have to do some error checking (now, only 8 different plots can be made. An error will result if you do more).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to pass command line parameters to a Flash projector in
Is there a way to pass a null value to a parameter in C#?
Is there a way to pass user credentials over a WCF service without using
Is there a way to pass a method as a parameter without knowing anything
Is there some way to pass system commands along with command line arguments in
is there a way to pass external parameter into Grid renderer function? For example,
Is there a way to pass a parameter (or multiple params) to the CallMethodAction
Is there any way to pass function as a parameter when starting a program
is there a way to pass a boolean to the addClicked method beside using
Is there a way to pass results generated within a PHP page (called into

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.