Skip to content

matlab annotation

November 28, 2016

x=[0.25,0.25];
y=[0.45,0.32];
a=annotation(‘textarrow’,x,y,’String’,’x_{2}(t), x_{14}(t)’);
set(a, ‘color’, myRed, ‘interpreter’, ‘tex’, ‘fontSize’, 15)

Advertisements

Matlab: plot multi-agent formation control

November 2, 2016

very easy to use!! just copy and paste to your m file and it works!!

Note: set up the input arguments

  • x_all_time
  • num
  • neighborMat
function fcn_myPlot(x_all_time)
global A d n
num=n;
neighborMat=A;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
graycolor=[0.5 0.5 0.5];
markersize=30;
textsize=25;
finalcolor=[0 0 1]*0.8;
%
figure;
hold on; box on; axis equal
% set label and tick
fontsize=20;
set(gca, 'fontSize', fontsize)
set(get(gca, 'xlabel'), 'String', 'x', 'fontSize', fontsize);
set(get(gca, 'ylabel'), 'String', 'y', 'fontSize', fontsize);
% hide label and tick
% set(gca, 'xtick', [])
% set(gca, 'ytick', [])
% boxcolor=0.7*ones(1,3);
% set(gca, 'xcolor', boxcolor)
% set(gca, 'ycolor', boxcolor)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot agent trajectory
for i=1:num
    xi_all=x_all_time.signals.values(:,2*i-1);
    yi_all=x_all_time.signals.values(:,2*i);
    plot(xi_all, yi_all, '--', 'color', graycolor);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initial formation
% for i=1:num
%     for j=i+1:num
%         if neighborMat(i,j)==1
%             pi=x_all_time.signals.values(1,2*i-1:2*i)';
%             pj=x_all_time.signals.values(1,2*j-1:2*j)';
%             line([pi(1),pj(1)], [pi(2),pj(2)], 'linewidth', 2, 'color', graycolor);
%         end
%     end
% end
for i=1:num
    xi_init=x_all_time.signals.values(1,2*i-1);
    yi_init=x_all_time.signals.values(1,2*i);
    plot(xi_init, yi_init, 'o', 'MarkerEdgeColor', graycolor, 'MarkerFaceColor', graycolor, 'markersize', 10)
end
% plot circles and text: initial
for i=1:num
    xi_init=x_all_time.signals.values(1,2*i-1);
    yi_init=x_all_time.signals.values(1,2*i);
    plot(xi_init, yi_init, 'o', ...
        'MarkerSize', markersize,...
        'linewidth', 2,...
        'MarkerEdgeColor', graycolor,...
        'markerFaceColor', 'white');
    text(xi_init, yi_init, num2str(i),...
        'color', graycolor, 'FontSize', textsize, 'horizontalAlignment', 'center', 'FontName', 'times');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% final formation
for i=1:num
    for j=i+1:num
        if neighborMat(i,j)==1
            pi=x_all_time.signals.values(end,2*i-1:2*i)';
            pj=x_all_time.signals.values(end,2*j-1:2*j)';
            line([pi(1),pj(1)], [pi(2),pj(2)], 'linewidth', 2, 'color', finalcolor);
        end
    end
end
% plot circles and text: final
for i=1:num
    xi_init=x_all_time.signals.values(end,2*i-1);
    yi_init=x_all_time.signals.values(end,2*i);
    plot(xi_init, yi_init, 'o', ...
        'MarkerSize', markersize,...
        'linewidth', 2,...
        'MarkerEdgeColor', finalcolor,...
        'markerFaceColor', [1 1 1]);
    text(xi_init, yi_init, num2str(i),...
        'color', finalcolor, 'FontSize', textsize, 'horizontalAlignment', 'center', 'FontName', 'times');
end
% % intermediate formation
% for k=1:size(x_all_time.time,1)
%     for i=1:num
%         for j=i+1:num
%             if neighborMat(i,j)==1
%                 pi=x_all_time.signals.values(k,2*i-1:2*i)';
%                 pj=x_all_time.signals.values(k,2*j-1:2*j)';
%                 line([pi(1),pj(1)], [pi(2),pj(2)], 'linewidth', 1, 'color', rand(1,3));
%             end
%         end
%     end
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set limit
xlim=get(gca, 'xlim');
ylim=get(gca, 'ylim');
delta=0.2;
xlim=xlim+[-delta,delta];
ylim=ylim+[-delta,delta];
set(gca, 'xlim', xlim, 'ylim', ylim);


Windows 10 – keyboard problem: apostrophe, single quote do not show up

November 2, 2016

Probelm: when I press the key on the top-left corner to type apostrophe or wavy line, it does not show up until I press another key.

Reason: that is because I used US-international keyboard layout. See the following using link. However, the link below does not match my system very much because my win 10 is more up to date and some settings are different.

http://superuser.com/questions/122625/apostrophes-and-double-quotes-dont-show-up-until-i-type-the-next-letter

Solution: in my system, search Languarge->change your langurate preferences->Options->add an input method-> choose “US” (not the one in the link)

Remove the previous “US-international”. Now it works!!

Useful keyboard shortcuts for MS Word

October 28, 2016

workable for Office 365

  • add bullet: control+shift+L
  • clear formatting: control+shift+N

Microsoft Word 2016 Autocorrection English

October 27, 2016

If you would like to change the languarate that the autocorrection is based on,

Review tab->Langurage->Set proofing languarage->Change the language from British to American and disable “Detect language automatically” (your computer is British)

You may also need to go to

File tab->Options->Language->Choose Editing language: from British to American English

Matlab cell, legend

July 22, 2016

str={};
for i=1:n
str=[str, strcat(‘idx=’,num2str(i))];
end
legend(str, ‘location’,’SouthWest’)

Read more…

Relation between eigenvalue and singular value

July 11, 2016

For any square matrix A, we have

-\sigma_{n-k+1}(A) \le \lambda_k\left(\frac{A+A^T}{2}\right) \le \sigma_k(A)

where 0\le\sigma_n\le\dots\le\sigma_1 are the singular values, and \lambda_n\le\dots\le \lambda_1 are the eigenvalues.

Proof of the right half of the inequality:

See Topics in matrix analysis: page 151, Corollary 3.1.5

Proof of the left half of the inequality:

First, we have

\lambda_k\left(\frac{-A-A^T}{2}\right)=-\lambda_{n-k+1}\left(\frac{A+A^T}{2}\right)

To verify, it is easy to see \lambda_1\left(\frac{-A-A^T}{2}\right)=-\lambda_{n}\left(\frac{A+A^T}{2}\right) and \lambda_n\left(\frac{-A-A^T}{2}\right)=-\lambda_{1}\left(\frac{A+A^T}{2}\right).

Second, applying the right half of the inequality gives

\lambda_k\left(\frac{A+A^T}{2}\right)=-\lambda_{n-k+1}\left(\frac{-A-A^T}{2}\right)\ge-\sigma_{n-k+1}(-A)=-\sigma_{n-k+1}(A)