Plotting and saving a Piecewise function with multiple inputs in matlab
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I included a piecewise function into my GUI matlab to draw a function at certain ranges.
syms Z
%define mean depth Z0
Z01= (4.*E.^1.6)/(r1.*0.8862269);% E and r1 are given by the user in an edit box
Z02= (4.*E.^1.6)/(r2.*0.8862269);% E and r2 are given by the user in an edit box
delat1=0.1;
delat2=0.002;
p3=-exp(-((Z-delat1)./Z01).^2);
p4=-exp(-((Z-delat2)./Z02).^2);
%------------
P3=(-p3.*(2*(Z-delat1)./Z01))./((Z01).^2);%
P4=(-p4.*(2*(Z-delat2)./Z02))./((Z02).^2);
P2L=piecewise(Z<d1, P3, d1<Z, P4)
%---------------------
% Plot Piecewise
%---------------------
axes(handles.axes1);
axis auto
fplot( P2L,[0 500],'linewidth',2)
xlabel('Pentration depth (nm)')
ylabel('P(Z,E)')
legend(strcat('E=',num2str(E(:)), 'keV'));
My problems:
1- the code works pretty fine with one value for 'E' but actually, I need to run the code with many values of E (from 0.5-35)
if I try to enter more than one value of E I get the error message:
Error using fplot (line 120)
Input must be a function handle or symbolic function.
2- How to save Z, P2L values to a text file like the first column shows Z and the second column shows P2L at the first E value, the third column shows P2L at the seconE value,...etc.
Could someone help?
Thanks in advance.
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!