# find closest points between two point set

point_set_1 =
20 482
19 359
45 438
61 248
90 403
104 95
149 335
148 392
161 73
186 29
188 236
189 319
200 162
208 70
204 198
203 343
214 250
225 307
233 171
238 205
237 245
253 148
264 362
281 34
300 341
306 88
305 203
328 234
326 164
330 20
364 199
424 241
433 314
491 187
point_set_2 =
99 399
104 95
149 335
148 392
158 82
184 238
190 320
202 343
236 246
263 361
299 342
330 20
493 193
%compute Euclidean distances:
for idx=1: length(point_set_1)
distances = sqrt(sum(bsxfun(@minus, point_set_2, point_set_1(idx,:)).^2,2));
%find the smallest distance and use that as an index into B:
closestForPin2toPin1(idx,:)= point_set_2(find(distances==min(distances)),:);
end

# foreign command atop frack or genfrac should be used instead(amsmath)

Using \atop is abusing its functionality; if you want to turn a screw, sometimes a knife can help, but a screwdriver is surely better.

In other words, use \substack that has been specifically defined for this task and can accommodate any number of lines. It’s also easier to use even for two lines.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$\sum_{1\le i\le n\atop i\ne j}\quad \sum_{\scriptstyle 1\le i\le n\atop\scriptstyle i\ne j}\quad \sum_{\substack{1\le i\le n\\ i\ne j}}$
\end{document}

The first is wrong; the second is complicated to write. With \substack you also avoid the warning

Package amsmath Warning: Foreign command \atop;
(amsmath)                \frac or \genfrac should be used instead
(amsmath)                 on input line 6.

https://tex.stackexchange.com/questions/153490/atop-vs-substack-for-multiple-lines-under-a-sum/153502

# Remove rows or cols whose elements are all NaN

For example,

A = [1 1 1 1 1 1 1 1 1 1;
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN;
1 1 1 1 1 1 1 1 1 1;
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN;];


should turned into

A = [1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1];

Use this :

   out = A(:,any(~isnan(A)));  % for columns
out = A(any(~isnan(A),2),:);   %for rows

or

A(~any(~isnan(A), 2),:)=[];

# “Compared with” vs “Compared to”

Use “compared with” when you are looking for differences.

E.g. CEO’s now earn 419 times the pay of blue-collar workers, compared with 42 times their pay in the 1980’s.

Use “compared to” when highlighting (or comparing) the similarities of one thing to another.

E.g. The human heart can be compared to a pump.

https://english.stackexchange.com/questions/583/compared-with-vs-compared-to-which-is-used-when

# Change histogram to curve in Matlab but not “fit”

Instead of automatically plotting a histogram using hist, you can get it to output the values:

[x, c] = hist(radius1,400);

x is the data in each bin, c the centre of each bin, so this replicates a histogram and then overplots a line on it (which will just connect the top of each bar so it may not look as smooth as you hoped):

bar(c,x);
hold on
plot(c,x,'r');

It is possible to use fit with an anonymous function as a custom model, but that may be overkill in this situation.

https://stackoverflow.com/a/22452076/4862158

# Matlab: applying norm function to rows of matrix

Solution1

 norms = sqrt(sum(A.^2,1))

or

 norms = sqrt(sum(A.^2,2))?

depending on whether your coordinates are in rows or in columns.

Solution2

If readability is a bigger consideration than performance you might also consider:

norms = cellfun(@norm,num2cell(A,2));

This pattern is also adaptable to other operations along one dimension you might want to perform where MATLAB doesn’t support it natively.

Solution3

From version 2017b onwards, you can use vecnorm.

# get IEEEtran to work with the subcaption package

The problem is that there does not seem to be a way to prevent subcaption from taking control of the main caption formatting away from IEEEtran like the caption=false option does under subfig.sty. IEEEtran has to format captions differently depending on its mode. An admittedly crude hack that might work is simply to restore IEEEtran’s definition of \@makecaption:

\makeatletter
\let\MYcaption\@makecaption
\makeatother

\usepackage[font=footnotesize]{subcaption}

\makeatletter
\let\@makecaption\MYcaption
\makeatother

And then code figures like:

\begin{figure*}[!p]
\begin{minipage}[b]{0.5\linewidth}
\centering
\includegraphics[width=2.5in]{box}%
\subcaption{Case I}\label{fig_first_case}%
\end{minipage}%
\hfil
\begin{minipage}[b]{0.5\linewidth}
\centering
\includegraphics[width=2.5in]{box}%
\subcaption{Case II}\label{fig_second_case}%
\end{minipage}%
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure*}

This did seem to work for me in one simple test, but more extensive testing is required.

http://www.michaelshell.org/tex/ieeetran/