how do i use imwrite

I have this code that plots a 3D Lorenz attractor. However when i try to write the plot to file using imwrite, it brings up an error:
Error in lorenzzz (line 31)
imwrite(Lorenzattractor,'Lattractor','.png');
>>
a=10; %sigma
b=8/3; %beta
r=28; %rho
h=0.004; %time step size dt
x=0;y=1; z=0;
f=zeros(1,3); %creates an array to hold the values of x,y,z
f=[x y z];
k=1; %the first row of the array
for t=0:h:100
k1_x=a*(y(k)-x(k));
k2_x=a*(y(k)-x(k))+(k1_x*h*0.5);
k3_x=a*(y(k)-x(k))+(k2_x*h*0.5);
k4_x=a*(y(k)-x(k))+(k3_x*h);
x(k+1)=x(k)+(k1_x+2*k2_x+2*k3_x+k4_x)*h/6; %value of x at t+1
k1_y=x(k)*(r-z(k))-y(k);
k2_y=(x(k)*(r-z(k))-y(k))+k1_y*h*0.5;
k3_y=(x(k)*(r-z(k))-y(k))+k2_y*h*0.5;
k4_y=(x(k)*(r-z(k))-y(k))+k3_y*h*0.5;
y(k+1)=y(k)+(k1_y+(2*k2_y)+(2*k3_y)+(k4_y))*h/6; %value of y at t+1
k1_z=x(k)*y(k)-b*z(k);
k2_z=(x(k)*y(k)-b*z(k))+k1_z*h*0.5;
k3_z=(x(k)*y(k)-b*z(k))+k2_z*h*0.5;
k4_z=(x(k)*y(k)-b*z(k))+k3_z*h*0.5;
z(k+1)=z(k)+(k1_z+(2*k2_z)+(2*k3_z)+(k4_z))*h/6; %value of z at t+1
k=k+1;
end
plot3(x,y,z); grid on;
xlabel('x'); ylabel('y');
zlabel('z');
title('Lorenzattractor');
%the code runs up to this point.
imwrite(Lorenzattractor,'Lattractor','.png');
brings error: Error in lorenzzz (line 31)
imwrite(Lorenzattractor,'Lattractor','.png');
>>

댓글 수: 2

Image Analyst
Image Analyst 2012년 10월 6일
Edit your post. Highlight your code. Click the {}Code icon to format like normal code.
Ejike
Ejike 2012년 10월 6일
I have done that

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2012년 10월 6일
편집: Image Analyst 2012년 10월 6일

0 개 추천

Ejike I answered this earlier this morning. However somehow your question got deleted. Thanks to Lazarus, I still have my deleted answer. Here it is:
*Ejike: You do not have a variable in your program called Lorenzattractor. Anyway, you should be using export_fig. See the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions.*
export_fig('Lattractor.png');
Also, please learn how to format your code. It's not hard, just make sure you have a blank line before it, then highlight all your code and click the {}Code icon above the edit box.

댓글 수: 2

Ejike
Ejike 2012년 10월 6일
thank you. will heed the advice. You have really bee
Image Analyst
Image Analyst 2012년 10월 7일
Actually it was in your duplicate question in the newsgroup: http://www.mathworks.com/matlabcentral/newsreader/view_thread/323589

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Language Support에 대해 자세히 알아보기

태그

질문:

2012년 10월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by