Drawing vertical lines in MATLAB
I am trying to draw 6 vertical and 6 horizontal lines on an image that are crossing each other and form cells. I am new to MATLAB and find it very confusing to find the right indexing.
So if I write the following:
f(60:60:end) = 255;
imshow(f)
I would get some vertical lines, but it is not the desired effect. Any suggestions?
See also questions close to this topic

Latex listings package cannot include matlab code with percentage symbol
I'm writing a Matlab project report using latex. I use
lstinputlisting
command inlistings
package to parse a Matlab code file.The original Matlab code has following lines.
s = functions(solvers{idx}); fname = s.function; fprintf("%s : \n", fname);
The percentage symbol in the code file trigger compile error.
! LaTeX Error: Environment CJK* undefined. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.19 fprintf("% s : \n", fname);
When I change the language from Matlab into C, the error disappear. I guess there are some bugs inside the Matlab syntax file inside listings package.
Is there any way to fix this problem?
My listings configuration is
\lstset{% language = Matlab, tabsize=4, frame=shadowbox, %把代码用带有阴影的框圈起来 commentstyle=\color{red!50!green!50!blue!50},%浅灰色的注释 rulesepcolor=\color{red!20!green!20!blue!20},%代码块边框为淡青色 keywordstyle=\color{blue!90}\bfseries, %代码关键字的颜色为蓝色，粗体 showstringspaces=false,%不显示代码字符串中间的空格标记 stringstyle=\ttfamily, % 代码字符串的特殊格式 keepspaces=true, % breakindent=22pt, % numbers=left,%左侧显示行号 往左靠,还可以为right，或none，即不加行号 stepnumber=1,%若设置为2，则显示行号为1,3,5，即stepnumber为公差,默认stepnumber=1 %numberstyle=\tiny, %行号字体用小号 numberstyle={\color[RGB]{0,192,192}\tiny} ,%设置行号的大小，大小有tiny,scriptsize,footnotesize,small,normalsize,large等 numbersep=8pt, %设置行号与代码的距离，默认是5pt basicstyle=\footnotesize, % 这句设置代码的大小 showspaces=false, % flexiblecolumns=true, % breaklines=true, %对过长的代码自动换行 breakautoindent=true,% breakindent=4em, % escapebegin=\begin{CJK*}{GBK}{hei},escapeend=\end{CJK*}, aboveskip=1em, %代码块边框 tabsize=2, showstringspaces=false, %不显示字符串中的空格 backgroundcolor=\color[RGB]{245,245,244}, %代码背景色 %backgroundcolor=\color[rgb]{0.91,0.91,0.91} %添加背景色 escapeinside=``, %在``里显示中文 %% added by http://bbs.ctex.org/viewthread.php?tid=53451 fontadjust, captionpos=t, framextopmargin=2pt,framexbottommargin=2pt,abovecaptionskip=3pt,belowcaptionskip=3pt, xleftmargin=4em,xrightmargin=4em, % 设定listing左右的空白 texcl=true, % 设定中文冲突，断行，列模式，数学环境输入，listing数字的样式 extendedchars=false,columns=flexible,mathescape=true % numbersep=1em }
And I use
\lstinputlisting{./code/main.m}
to include file. 
Distance Calculations for Nearest Mean Classifer
Greetins,
How can I calculate how many distance calculations would need to be performed to classify the IRIS dataset using Nearest Mean Classifier.
I know that IRIS dataset has 4 features and every record is classified according to 3 different labels.
According to some textbooks, the calculation can be carried out as follow:
However, I am lost on these different notations and what does this equation mean. For example, what is s^2 is in the equation?

matlab: addition of symbolic matrices along an unused dimension
How can symbolic matrices collected in a cell array be summed along an unused dimension? Assume, for reasons beyond the scope of this post, that the matrices must be the elements of a cell array, rather than planes of a higherdimensional matrix. What follows is a brief demonstration of the problem.
Suppose we have a cell array of 2D
sym
vectors prepared as follows:a = vpa(ones(2,2)); c = {a; 2*a; 3*a};
Despite the fact that it is possible to make multidimensional symbolic matrices with newer versions of matlab (e.g.,
sym('c', [2 2 2])
), addition of 2Dsym
matrices along a third dimension failssum(cat(3, c{:}), 3) Error using symengine Arguments must be 2dimensional.
With numeric inputs, the operation is successful:
a = ones(2,2); c = {a; 2*a; 3*a}; sum(cat(3,c{:}), 3) 6 6 6 6
Edit:
In fact, the problem of multidimensional addition is more general than I had thought:
sum
cannot be applied to anysym
matrix of dimensionality greater than 2.a=vpa(ones(2,2)); sum(a,1) [ 2.0, 2.0] sum(a,2) 2.0 2.0 a = vpa(ones(2,2,2)); sum(a,1) % fails sum(a,2) % fails sum(a,3) % fails
Manual addition of planes along a third dimension works, so iterative addition is an option, though
sum
would be preferable:a=vpa(ones(2,2,2)); plus(a(:,:,1), a(:,:,2)) [ 2.0, 2.0] [ 2.0, 2.0]
Edit #2:
According to this page, the problem is apparently unavoidable since support for dimensionality >2 is explicitly not offered.
Unlike the MATLAB® sum, the symbolic sum function does not work on multidimensional arrays. For details, follow the MATLAB sum page.
Nevertheless, suggestions on alternatives are still welcome.