1.Suppose we want the user to give an input.This we do using the following format:
x=input('statement' );
where x is assigned the input value.Here x is a real number.
Sometimes we want the user to give an input that may be some character or any string.In that case we use the following format:
x=input('statement','s');
Here x is assigned the character or string value.And this is indicated by 's' which stands for string type.
2.We have already seen a few examples where we want to produce some numerical output.However in case of some string we use the sprintf() or disp() function.
eg.,
sprintf('I know matlab')
or disp('I know matlab')
or frpintf('I know matlab')
gives the output:
ans=
I know matlab
3.Now suppose you want to display a value of any variable within a statement you can this as follows:
eg.,
i=5;
fprintf('the value for i is %d',i);
Here the output goes like this:
the value of i is 5
thus the %d is replaced by the value of i.Now if there are more than one variables then it's nothing different from the previous example:
eg.,
i=5;
j=8;
fprintf('%d is greater than %d',j,i);
Here the first %d is replaced by j and the second %d is replaced by i.Hence the output is:
8 is greater than 5
4.If you want to add a new line or a tab or a carriage return use the following symbols inside the fprintf function:
\n for new line,i.e.,goes to the next line and places the cursor at the beginning.
\t for a tab
\r for a carriage return,i.e., returning the cursor to the intial position of the row.
eg.,
if you want to display:
what is this?
i don't know
do it like this:
fprintf('what is this?\ni don't know\n');
The \n moves the cursor to the new line and prints the next words from the fresh start.
PLEASE LEAVE A COMMENT :)
x=input('statement' );
where x is assigned the input value.Here x is a real number.
Sometimes we want the user to give an input that may be some character or any string.In that case we use the following format:
x=input('statement','s');
Here x is assigned the character or string value.And this is indicated by 's' which stands for string type.
2.We have already seen a few examples where we want to produce some numerical output.However in case of some string we use the sprintf() or disp() function.
eg.,
sprintf('I know matlab')
or disp('I know matlab')
or frpintf('I know matlab')
gives the output:
ans=
I know matlab
3.Now suppose you want to display a value of any variable within a statement you can this as follows:
eg.,
i=5;
fprintf('the value for i is %d',i);
Here the output goes like this:
the value of i is 5
thus the %d is replaced by the value of i.Now if there are more than one variables then it's nothing different from the previous example:
eg.,
i=5;
j=8;
fprintf('%d is greater than %d',j,i);
Here the first %d is replaced by j and the second %d is replaced by i.Hence the output is:
8 is greater than 5
4.If you want to add a new line or a tab or a carriage return use the following symbols inside the fprintf function:
\n for new line,i.e.,goes to the next line and places the cursor at the beginning.
\t for a tab
\r for a carriage return,i.e., returning the cursor to the intial position of the row.
eg.,
if you want to display:
what is this?
i don't know
do it like this:
fprintf('what is this?\ni don't know\n');
The \n moves the cursor to the new line and prints the next words from the fresh start.
PLEASE LEAVE A COMMENT :)
18 comments:
hello there i see you are familiar with matlab can you help me with a question it will be much appreciated....
http://img42.imageshack.us/i/11678119.png/
hey jun...it's easy.you could have tried yourself.Anyways here's what I thought:
function ideal_body_weight
x=input('Enter m for man,w for woman: ','s');
h=input('\nEnter your height in inches: ');
if(x=='m')
idb=50+2.3*(h-60);
else if(x=='w')
idb=45.5+2.3*(h-60);
end
end
fprintf('\nThe ideal weight is %g kg.\n',idb);
however check if your algorithm is right o not,because you will get negative results for people with height less than 60inches.
omg thank you so much its because im new to thiss i got the 1st and 2nd step correct it was just the if formula but thanks again you are awesomee!! if you dont mind could you help me with another one its much harder like reading it makes me cry....:)
http://img593.imageshack.us/i/65125930.png/
I think you should do it yourself first and tell me how far you got.then i will surely help you.
hello well i done this so far :-
E=2.1*exp(11);
I=4.573*exp(-4);
L=10;
W=50;
a=0:0.1:10;
b=L-a;
if a>or=b
xmax=(sqrt(a.*(a+2*b)/3))
ymax=-((W*a.*b)/(27*E*I*L))*(b+2*a)*(sqrt(3*a.*(a.+2*b))
if else a<b
yymax=-((W*a.*b)/(27*E*I*L))*(a+2*b)*(sqrt(3*b.*(b.+2*a))
but it doesnt work i know how to plot the graph but need to get these data points please help with part 1) :).
there are a few mistakes.probably that's why it didn't work out.try this and check where you went wrong.ask me if you still don't get it.
function plotting1
E=2.1*(10^11);
I=4.573*(10^(-4));
L=10;
W=50000;
i=1;
for a=0:0.1:10
b=L-a;
if (a>=b)
xmax(i)=(sqrt(a*(a+2*b)/3));
ymax(i)=-((W*a*b)/(27*E*I*L))*(a+2*b)*(sqrt(3*a*(a+2*b)));
else if (a<b)
xmax(i)=L-sqrt((b*(b+2*a))/3);
ymax(i)=-((W*a*b)/(27*E*I*L))*(b+2*a)*(sqrt(3*b*(b+2*a)));
end
end
i=i+1;
end
hmmm i get it jus gotta learn the proper syntax for matlab altho i dnt get what i is for??
you are creating a row matrix of length given by the final value of i-1.and at each column indexed by i stores the calculated.you can compare this with a block of houses at a certain street and you are assigning who's to stay at which house in the block.
and yeah learn the proper syntax.it's pretty easy for matlab.
Oh good analogy...do you know how to simulate differntial equations of second order on matlab?
http://img696.imageshack.us/img696/797/dvdtz.jpg
dsolve('D2v+11*Dv+(10+5*Kt)*v-5*m=0')
now D2v refers to the second order derivative of v w.r.t. t.D in general means (d/dt).
dsolve is a special function used to solve differential functions.
hmmm do you have to take the 5m to the other said to make it equal zero... and how do i plot this with kt with certain values as such..
http://img33.imageshack.us/i/q3b0.png/
side*
firstly no you don't have to take it to the other side. and just put some values to kt and plot it.change it and see the different plots.
use a loop.
and use hold on.
it will help you plot on the same graph
hold off to end the plot.
you can use different colours
just try like this
plot(n,y,'red')
hii can you explain to me the diffrence between A/B and A\B? i know its something about left and right matrix divide??
http://img189.imageshack.us/img189/1014/35696812.png how do i do this i knw the index is 1:5 but how do i make it the power of the array??
A/B is the solution for XA=B.Hence X=A.inverse(B)
A\B is the solution for AX=B.Hence X=inverse(A).B
sorry for the delay.had an exam.i have a solution for the last problem.
I have posted it under matlab operations...
Post a Comment