Moe Chong
Moe Chong

Reputation: 23

MatLab Plotting Multiple Data Sets (Same Graph)

My question concerns wanting to plot information using MatLab. I am having a lot of trouble as I am fairly new to the platform.

I would like to plot this information with x being linearly scaled and y being log scaled. I would also like to plot 2^n with the provided information below

   n         Original           Improvement 1       Improvement2  
  10        1,198,861               2,127,920          1,900,916 
  30        2,501,876               2,086,086          8,255,021 
  50       69,448,535              18,677,001          3,429,279 
  70       67,754,271              22,712,979         33,856,555 
  90      282,232,302              33,509,532         80,645,811 
 110   52,066,961,922           5,452,933,038      1,544,349,121 
 130   13,900,123,332          67,027,087,188      3,786,963,385 

I am required to graph this date in order to examine the different values of Original, Improvement1 and improvement2 and 2^n

Log and n will be the axis for this graph.

Any help is greatly appreciated.

Upvotes: 0

Views: 1336

Answers (1)

user2999345
user2999345

Reputation: 4195

use semilogy or just log, depends on how you want your y-axis to look like:

data = [  10        1198861               2127920          1900916 ;
    30        2501876               2086086          8255021 ;
    50       69448535              18677001          3429279 ;
    70       67754271              22712979         33856555 ;
    90      282232302              33509532         80645811 ;
    110   52066961922           5452933038      1544349121 ;
    130   13900123332          67027087188      3786963385 ];

n = data(:,1);
Original = data(:,2);
Improvement1 = data(:,3);
Improvement2 = data(:,4);
nsqr = n.^2;

subplot(121);
semilogy(n,Original,n,Improvement1,n,Improvement2,n,nsqr);
xlim([n(1) n(end)]);
legend('Original','Improvement1','Improvement2','n^2');
title('using semilogy')

subplot(122);
plot(n,log(Original),n,log(Improvement1),n,log(Improvement2),n,log(nsqr));
xlim([n(1) n(end)]);
legend('Original','Improvement1','Improvement2','n^2');
title('using log')

enter image description here

Upvotes: 1

Related Questions