unable to plot graph as well as form a table as it is taking only last value of the loop,plz help me in this particular matter as i ve my submission on coming friday
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ellora
le 21 Jan 2014
Réponse apportée : AJ von Alt
le 21 Jan 2014
Y1 =
7.7054
Y2 =
9.6584
I(1)= -0.0159
I(2)=-0.0128
I(3)=-0.0043
I(4)=0.4141
I(5)=0.2673
I(6)=-0.0043
for y=0.45:-0.05:0.25
ud=(I(3)*exp(Y2*y)+I(4)*exp(-Y2*y)+k2)^0.5;
taub=(f*ro*ud^2)/8;
end
for y=0.25:-0.05:0
ud=(I(1)*exp(Y1*y)+(I(2)*exp(-Y1*y))+k1)^0.5;
taub=(f*ro*ud^2)/8;
end
for y=0.0:-0.05:-0.25
ud=(I(1)*exp(-Y1*y)+(I(2)*exp(Y1*y))+k1)^0.5;
taub=(f*ro*ud^2)/8;
end
for y=-0.25:-0.05:-0.45
ud=(I(3)*exp(-Y3*y)+I(4)*exp(Y3*y)+k2)^0.5;
taub=(f*ro*ud^2)/8;
end
table1=[y,ud]; table2=[y,taub]; fid1=fopen('depth averaged value.txt','w'); fid2=fopen('boundary shear.txt','w'); fprintf(fid1,' m m/s \n'); fprintf(fid1,'%8.2f %8.2f\n',table1); fprintf(fid2,' m N/m^2 \n'); fprintf(fid2,'%8.2f %8.2f\n',table2); fclose(fid1); fclose(fid2); plot(y,ud)
0 commentaires
Réponse acceptée
AJ von Alt
le 21 Jan 2014
The code for generating the table and printing it to a file is correct, but the variables y, ud, and taub are all scalars. Each iteration of each for loop overwrites the previous values of y, ud, and taub.
One way to solve this problem is to make the variables vectors and store the result of each calculation as an element of the corresponding vector.
See the indexing documentation for information on how to access data in vectors and matrices and the for loop documentation for an example of how to store and retrieve data in a vector using a for loop.
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!