Thread Subject: M-File - How to input ?

Subject: M-File - How to input ?

From: Ahmad

Date: 3 Nov, 2009 18:13:02

Message: 1 of 5

If I want to input a function without a gui then how can I do it so that the M-file is a exe and still asks user for input and executes code line-by-line and then asks for input in whichever line it is required?

In the following I want to input g,a,b, and tol from user. How can I get this done?

syms x
g=?
dg=diff(g,x);
f=sym2poly(g);
df=sym2poly(dg);

a=?
b=?
tol=?
itr=2;
itrr=50;

for i=1:itr
p=(a+b)/2;
if(polyval(f,a)*polyval(f,p)<0)
b=p;
else
a=p;
end
end
s=p;

for j=1:itrr
s1=s-polyval(f,s)/polyval(df,s)
if(polyval(f,s)==0|[abs(s-s1)/s]<tol)
break
else
s=s1
end
end

Subject: M-File - How to input ?

From: ade77

Date: 3 Nov, 2009 18:24:02

Message: 2 of 5

use inputdlg
for example;
g = inputdlg('enter the value of g'), will display a dialog box, where the user can enter the value of g.
type doc inputdlg at the command prompt to get more options on this function

"Ahmad " <climber65@gmail.com> wrote in message <hcprre$sfp$1@fred.mathworks.com>...
> If I want to input a function without a gui then how can I do it so that the M-file is a exe and still asks user for input and executes code line-by-line and then asks for input in whichever line it is required?
>
> In the following I want to input g,a,b, and tol from user. How can I get this done?
>
> syms x
> g=?
> dg=diff(g,x);
> f=sym2poly(g);
> df=sym2poly(dg);
>
> a=?
> b=?
> tol=?
> itr=2;
> itrr=50;
>
> for i=1:itr
> p=(a+b)/2;
> if(polyval(f,a)*polyval(f,p)<0)
> b=p;
> else
> a=p;
> end
> end
> s=p;
>
> for j=1:itrr
> s1=s-polyval(f,s)/polyval(df,s)
> if(polyval(f,s)==0|[abs(s-s1)/s]<tol)
> break
> else
> s=s1
> end
> end

Subject: M-File - How to input ?

From: Sebastiaan

Date: 3 Nov, 2009 18:29:05

Message: 3 of 5

"Ahmad " <climber65@gmail.com> wrote in message <hcprre$sfp$1@fred.mathworks.com>...
> If I want to input a function without a gui then how can I do it so that the M-file is a exe and still asks user for input and executes code line-by-line and then asks for input in whichever line it is required?
>
> In the following I want to input g,a,b, and tol from user. How can I get this done?
>
help input

Sebastiaan

Subject: M-File - How to input ?

From: Ahmad

Date: 3 Nov, 2009 19:27:02

Message: 4 of 5

"ade77 " <ade100a@gmail.com> wrote in message <hcpsg2$aqj$1@fred.mathworks.com>...
> use inputdlg
> for example;
> g = inputdlg('enter the value of g'), will display a dialog box, where the user can enter the value of g.
> type doc inputdlg at the command prompt to get more options on this function
>
> "Ahmad " <climber65@gmail.com> wrote in message <hcprre$sfp$1@fred.mathworks.com>...
> > If I want to input a function without a gui then how can I do it so that the M-file is a exe and still asks user for input and executes code line-by-line and then asks for input in whichever line it is required?
> >
> > In the following I want to input g,a,b, and tol from user. How can I get this done?
> >
> > syms x
> > g=?
> > dg=diff(g,x);
> > f=sym2poly(g);
> > df=sym2poly(dg);
> >
> > a=?
> > b=?
> > tol=?
> > itr=2;
> > itrr=50;
> >
> > for i=1:itr
> > p=(a+b)/2;
> > if(polyval(f,a)*polyval(f,p)<0)
> > b=p;
> > else
> > a=p;
> > end
> > end
> > s=p;
> >
> > for j=1:itrr
> > s1=s-polyval(f,s)/polyval(df,s)
> > if(polyval(f,s)==0|[abs(s-s1)/s]<tol)
> > break
> > else
> > s=s1
> > end
> > end

thx

Subject: M-File - How to input ?

From: ade77

Date: 3 Nov, 2009 20:06:02

Message: 5 of 5

Sebastine already gave you that answer.

g = input('enter the value of g');
b = input('enter the value of b');
a = input('enter the value of a');
tol= input('enter the value of tol');

you can change the string quote to your satisfaction.

"Ahmad " <climber65@gmail.com> wrote in message <hcq066$535$1@fred.mathworks.com>...
> "ade77 " <ade100a@gmail.com> wrote in message <hcpsg2$aqj$1@fred.mathworks.com>...
> > use inputdlg
> > for example;
> > g = inputdlg('enter the value of g'), will display a dialog box, where the user can enter the value of g.
> > type doc inputdlg at the command prompt to get more options on this function
> >
> > "Ahmad " <climber65@gmail.com> wrote in message <hcprre$sfp$1@fred.mathworks.com>...
> > > If I want to input a function without a gui then how can I do it so that the M-file is a exe and still asks user for input and executes code line-by-line and then asks for input in whichever line it is required?
> > >
> > > In the following I want to input g,a,b, and tol from user. How can I get this done?
> > >
> > > syms x
> > > g=?
> > > dg=diff(g,x);
> > > f=sym2poly(g);
> > > df=sym2poly(dg);
> > >
> > > a=?
> > > b=?
> > > tol=?
> > > itr=2;
> > > itrr=50;
> > >
> > > for i=1:itr
> > > p=(a+b)/2;
> > > if(polyval(f,a)*polyval(f,p)<0)
> > > b=p;
> > > else
> > > a=p;
> > > end
> > > end
> > > s=p;
> > >
> > > for j=1:itrr
> > > s1=s-polyval(f,s)/polyval(df,s)
> > > if(polyval(f,s)==0|[abs(s-s1)/s]<tol)
> > > break
> > > else
> > > s=s1
> > > end
> > > end
>
> thx

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com