Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how do i get it to draw a proper graph so far im getting a straight line

Subject: how do i get it to draw a proper graph so far im getting a straight line

From: raaj kumar

Date: 10 Nov, 2010 13:48:03

Message: 1 of 2

hey guys i have a problem , i wanna draw a graph with many lines representing diff pressures but i just end up getting straight lines along the same points!
program:

function [r] = edi(n, p)
%program t calculate protein release
%constants
Kp=4.1399e-8;
a=2.8;

%operation conditions
N=5
P=500

%Protein release
r=(1-1/exp(Kp*(P^a)*N));





p=650;
for i= 1:7
    n(i)=i-1;
   r(1,i) = edi(n(i), p);
p=600;
for i=1:7
    n(i)= i-1;
r(2,i) = edi(n(i), p);
p=550;
for i=1:7
    n(i) = i-1;
    r(3,i)=edi(n(i),p);
    for i=1:7
        n(i) = i-1;
        r(3,i)=edi (n(i), p);
    end
end
end
end
    


plot(n, r(1,:),'ro-')
hold on
plot (n, r(2,:), 'b*-')
hold on,
plot (n, r(3,:),'g:')

Subject: how do i get it to draw a proper graph so far im getting a straight

From: dpb

Date: 10 Nov, 2010 20:51:04

Message: 2 of 2

raaj kumar wrote:
> hey guys i have a problem , i wanna draw a graph with many lines
> representing diff pressures but i just end up getting straight lines
> along the same points!
> program:
>
> function [r] = edi(n, p)
> %program t calculate protein release
> %constants
> Kp=4.1399e-8;
> a=2.8;
>
> %operation conditions
> N=5
> P=500
>
> %Protein release
> r=(1-1/exp(Kp*(P^a)*N));

First, you have 'p' as the dummy argument but use 'P' in the function

ML is case-sensitive so p doesn't matter internally.

Further, if P is supposed to be p, then the line

P=500 would overwrite the passed value anyway. If that is to be the
same, then remove that assignment completely and either use lower case
or upper case "p" consistently throughout.

You have the same problem w/ the variables "n" and "N"

After that, there doesn't seem any reason to not vectorize the function
at least on the n

r=(1-1/exp(Kp*(p^a).*N));
...

Then the other could be rewritten as sotoo...

P = [650:-50:550]; %
n = [0:7];
r = zeros(length(p),length(n)); % preallocate
for idx=1:length(P)
   r(idx,:) = edi(n, P(idx))
end
> plot(n, r(1,:),'ro-')
> hold on
> plot (n, r(2,:), 'b*-')
> hold on,
> plot (n, r(3,:),'g:')

Untested, but at least a start...

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us