clear %% Find % Logical Operation, p.8 % A=[ 0, 0,-2; 0 -1 -1; -2 -2 0]; % add semicolon - look at warning! index=find(A); % single numeration [i,j,a]=find(A); for k=1:nnz(A) disp([i(k),j(k),a(k)]); % or [i(k),j(k),a(k)] end %---------------------------- [i,j]=find(A==-2) % with\without semicolon [i(:),j(:)] %---------------------------- A==-2; A(A==-2)=pi %---------------------------- %% Functions all & any, p.9-10 clear % all A=randi(9,5); L=A==A'; % issymmetric(A), isequal(A,A')? all(L); % all(L(:)) S=A*A'; all(all(S==S')); % any minA=min(A(:)); % or minA=min(min(A)) B=A-minA; % contain zero x=sort(B(:)) y=1./x; logInd=isinf(y) % help isrow (iscolumn,islogical,isempty,isfinite,isnan, isstruct,...) x(logInd)=[]; y(logInd)=[] % ? % or x=x(isfinite(y)), % ? % y=y(isfinite(y)) % plot(x,y) % %% p.14 How do choose code, using presentation? Much better browser Edge! % show step by step! %% code is ready clear x=-pi:pi/24:pi; y= sin(x)./x; % векторная операция z=log((1+x.*sign(x))); subplot(1,3,1); plot(x,y); hold on; plot(x,z,'r-'); legend('sin(x)/x',... 'log((1+x.*sign(x)))'); subplot(1,3,2); % clear x % (если хотите) x=linspace(1.6,3.1415,100); % z=[sin(x)', tan(x)', sqrt(x)' x.^2']; r=plot(z); legend({'sin','tan','sqrt','x.^2'}) subplot(1,3,3) plot(x,z); legend({'sin(x)','tan(x)',... 'sqrt(x)','x.^2'}); set(r(:),'linewidth',2); set(gca,'fontsize',14); set(r(1)) % all structure's fields set(r(1),'Marker') set(r(1),'LineStyle') %% plpotyy yyaxis p.15 figure % for different growth: plotyy(x,sin(x),x,z(:,2)) % the first way figure yyaxis left % the second way plot(x,sin(x)) gcl=gca set(gca) yyaxis right plot(x,z(:,2)) gcr=gca chr=get(gcr, "Children") % design set(chr, "LineWidth",2) %% code p.15 -> comment clear x=-pi:pi/24:1.4*pi; y= sin(x); z=exp(x); subplot(1,2,1); title('sin(x) {\it падает} на ось X') plot(x,y,'m--','linewidth',2); hold on plot(x,z,'c:','linewidth',2); lg1=legend('y=sin(x)','z=exp(x)'); lg1.FontSize=14; xlabel('x'), yl=ylabel('y,z','rotation',0), yl.FontSize=14 set(gca,'fontsize',14) subplot(1,2,2); title('Каждому – свой Y!') [haxes,line1,line2]=plotyy(x,y,x,z); line1.LineWidth=2; line2.LineWidth=2; xlabel('x'); grid on; ylabel(haxes(1),'y','rotation',0); ylabel(haxes(2),'z','rotation',0); legend('y=sin(x)','z=exp(x'); set(haxes(1),'fontsize',14); set(haxes(2),'fontsize',14)