How to plot a matlab function for different parameters using hold on command -


i have matlab function contain constant parameter, want draw function, on same figure, using hold on (probably) while changing value of constant. code:

close clear clc m = 5; x = 1:1:10; y = m*x + 10; h1 = figure; plot(x,y) m = 10; figure(h1); hold on plot(x,y,': r') 

when tried using code, got 2 lines coincident on each others; , looks matlab used last value parameter m how can make use different values. found stuff here, doesn't fulfill needs. suggestions?

you need recalculate y well:

m = 5; x = 1:1:10; y = m*x + 10;  h1 = figure; plot(x,y); hold on;  m = 10; y = m*x + 10;  figure(h1); plot(x,y,': r') 

or create anonymous function:

x = 1:1:10; f = @(m) m*x + 10;  %// , then: h1 = figure; plot(x,f(5)       ); hold on; plot(x,f(10),': r'); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -