Randomly picking a column index depending on the weight of its value (MATLAB) 
Use randsample (Statistics Toolbox), which allows
you to specify weights:
col = randsample(1:size(A,2), 1, true, weight);
and then your column is A(:,col).
If you don't have the Statistics Toolbox:
col = sum(rand<cumsum(weight));

Printing simulink model to JPEG image 
Check Create a Print Frame in the documentation,
you need to use the frameedit function. There is a
lot more stuff about printing in the documentation
under Print and Export Models, I strongly suggest
you have a read.

Convert RGB to Grayscale while keeping maximum quality 
The issue here is that your image has a depth of
24 bits but you convert it to an 8 bit greyscale
using the solution you linked. I presume ImageJ
does the same thing by default.
I think you can fix this by replacing 255 with
(2^24)1 in the line
map = [(0:255)' (0:255)' (0:255)']/255;
and uint8 to uint32 on the next line.

find a value or the most similar value to an item in an array 
You're close. To avoid the problem with the
negative values, you can use abs to take the
absolute value. You can then get the closest value
using the second output of min:
value=3;
array=[1,2,5,6,9];
cur = abs(arrayvalue);
% df is the minimum distance, ind is the index of
the minimum distance
[df,ind] = min(cur);
theneededvalue = array(ind);

How to vectorize a piecewise periodic function in MATLAB? 
You need to change your syntax slightly to be able
to handle data of any size. I typically use
logical filters to vectorise ifstatements, as
you're trying to do:
function v = foo(t)
v = zeros(size(t));
t = mod( t, 2 ) ;
filt1 = t<0.1;
filt2 = ~filt1 & t<0.2;
filt3 = ~filt1 & ~filt2;
v(filt1) = 0;
v(filt2) = 10*t(filt2)1;
v(filt3) = 1;
In this code, we've got three logical fil

Calculate average from a series with fixed interval 
The number of elements in your original series
will always be a multiple of 12, so you can use
reshape() to yield an 12 x n matrix. From there
using mean() is straightforward to get the vector
that you want.
nSessions = 20; % Choose an integer to test number
of sessions
TestData = 1:12; % Dummy data  col 1 = 1, col 2 =
2...to check that our reshaping is correct
data = repmat(TestData, 1, nSes

How to remove a scalar structure in MATLAB? 
I'm sure this was answered several times but it's
just a common one liner in matlab:
flat_final = [final{:}]
To make the answer more complete you could use
horzcat, vertcat and reshape to finetune your
results.
The technical term for your task is flatten so you
might find many more snippets if you search for
it.

How can I produce a MATLAB bar graph of categorical responses? 
Try this. First I created some sample data, for 10
students answering 5 questions:
choices=['A' 'B' 'C' 'D'] %// I'll use this
variable later as well
for m=1:10
for n=1:5
answers{m,n}=choices(randi(4));
end
end
answers
Then to find the frequency of each answer to each
question, freq, I looked at each response
individually, and counted up how many students
gave that answer to tha

How can a function have multiple return values in Julia (vs. MATLAB)? 
How would I define my stat function in Julia?
function stat(x)
n = length(x)
m = sum(x)/n
s = sqrt(sum((xm).^2/n))
return m, s
end
For more details, see the section entitled
Multiple Return Values in the Julia documentation:
In Julia, one returns a tuple of values to
simulate returning multiple values. [...]

converge values to range [pi,pi] in matlab, NOT using wraptopi 
To expand on @Ben Voight, you could use
modulostyle operations this way:
To wrap to [0, 2*pi], you'd do this:
angle_rad = angle_rad 
2*pi*floor(angle_rad/(2*pi));
To wrap to [pi, +pi], you'd add another term
angle_rad = angle_rad  2*pi*floor(
(angle_rad+pi)/(2*pi) );

Sort complex matrix and vector together in specific order 
Answer is also very similar :)
negIm = imag(e) < 0;
[e1,ie1] = sort(e(~negIm));
[e2,ie2] = sort(e(negIm));
newe = cat(1,e1,e2);
v1 = v(:,~negIm); v2 = v(:,negIm);
newv = cat(2,v1(:,ie1),v2(:,ie2));

How do I determine the coefficients for a linear regression line in MATLAB? 
Judging from the link you provided, and my
understanding of your problem, you want to
calculate the line of best fit for a set of data
points. You also want to do this from first
principles. This will require some basic Calculus
as well as some linear algebra for solving a 2 x 2
system of equations. If you recall from linear
regression theory, we wish to find the best slope
m and intercept b su

Normalized cut: what does this code do? 
I believe you came across a piece of code written
by Prof Stella X Yu.
Indeed, when W is positive this code has no effect
and this is the usual case for NCuts.
However, in a CVPR 2001 paper Yu and Shi extend
NCuts to handle negative interactions as well as
positive ones. In these circumstances dr (r for
"repulsion") plays a significant role.
Speaking of negative weights, I must say that
personall

How to convert uncompressed (*.LJPGEG.1) images of DDSM database into PNG format for all scanners 
I have written a small utility to easily download,
convert, view and get annotations from DDSM data,
without the need for any manual work. The utility
makes getting the DDSM database totally automatic,
and is designed to help researchers. You just need
to download the required cases and then follow the
instructions on how to use my utility to convert
the LJPEG files to LJPEG1 and then to other for

Inversion and point subtraction on Elliptic Curve 
I can help you in finding negative coordinate of
y. I am explaining with a toy example:
sum = [673 146]
% Now to convert 2nd element of sum which is the y
coordinate, do the following.
sum(1,2) = sum(1,2) % this will negate the 2nd
element of 1st row of sum and store the result
into sum.
% now to perform subtraction, do the following.
Assume that your addend is N1 = [ 6,5] and augend
is the s

Plot a figure in which there is an image that moves and rotates 
Here is an example to start with,
This is the simplified code in here.
load topo
n = size(topomap1,1);
topo = (topo  min(topo(:))) ./ range(topo(:));
I = ind2rgb(round(topo*(n1)+1), topomap1);
[X,Y,Z] = sphere(n);
for i = 1 : n
[az,el,r] = cart2sph(X,Y,Z);
az = az + 2 / n * pi;
[X,Y,Z] = sph2cart(az,el,r);
warp(X,Y,Z,I)
axis equal off
pause(.1)
end
You can change I

Jacobi to GaussSeidel 
The difference between a Jacobi solver and a
GaussSeidel solver is that when you're solving
for the solution of a variable x_i at the current
iteration, you need to use the information from
the previous variables (x_1, x_2, ..., x_{i1}) as
part of the solution for the current variable x_i.
For Jacobi, you are simply using the previous
iteration's solution to formulate the current
solution. For

Efficient way of using ssim() function in Matlab for comparing image structures (or any other alternative) 
Never mind, here I'm going through all image
pairs, twice (switched parameters), which is not
needed.So it is possible to reduce the speed by
n1/2.
If you want efficiency over accuracy (which in my
case, it is), finding the score from the
correlation of histograms is one possible way.
It took me 55 seconds to process 72 frames with
ssim(), while only 1.2 seconds with difference of
histograms.

Sum of element in Vector to get the correspond Matrix 
You could think about the problem in a different
way  essentially what you're calculating is the
average of the distance between the start points
of each facility and the end points of each
facility. i.e.
<start dist>
[ A ][ B ][ C ][ D
]
<end
dist>
You can calculate the start a

How to implement a derivative of a symbolic function by a 'symfun' in Matlab? 
In newer versions of Matlab (I'm using R2014b) the
error message is clearer:
Error using sym/diff (line 26)
All arguments, except for the first one, must
not be symbolic functions.
So, it looks like sym/diff cannot take a
derivative with respect to what the documentation
calls an abstract or arbitrary symfun, i.e., one
without a definition. This limitation is not
explicitly mentioned in th

How to find the decision boundary for two set of data for knn classifier 
For simply visualizing the decision boundary and
decision regions, it is often satisfactory to
bruteforce test your whole domain of interest.
Specifically, you'd define a set of discrete
points that span your domain of interest, you'd
step through each point evaluating to which class
the point belongs, then you'd plot the results.
Maybe something like this:
%define your domain of interest
dx

Spatial cross correlation field of matrix 
Simply search for values in pval that are less
than 0.001, then use this to index into corelMat
and set those values to zero. As such:
corelMat(pval < 0.001) = 0;
pval < 0.001 generates a logical matrix where
true denotes those pvalues that are less than
0.001 and false otherwise. By providing a logical
matrix that is the same size as corelMat as an
argument into corelMat, you are only

Substitute value to Matrices by given a Row Vector and Their Corresponding Location Matrix 
Pretty easy. Simply use A to index into B:
A = [2 4 1 5 3;
5 2 3 4 1;
1 2 3 4 5];
B = [0.05 0.03 0.06 0.04 0.02];
B(A)
ans =
0.0300 0.0400 0.0500 0.0200 0.0600
0.0200 0.0300 0.0600 0.0400 0.0500
0.0500 0.0300 0.0600 0.0400 0.0200
You're probably thinking... woah!... how the heck
does this work? Because of how A is structured,
eac

image filtering separable matrix speed MATLAB 
It seems like an optimization error.
I'd use the function conv2 instead.
Let's write a sample code:
mOutputImage = conv2((vFilterCoeff.' *
vFilterCoeff), mInputImage);
mOutputImageSep = conv2(vFilterCoeff,
vFilterCoeff.', mInputImage);
Try those in a loop where the length of
vFilterCoeff (Row Vector!!!) is getting bigger.
update us what are the result now.

How to assign key to push button on Matlab? 
The KeyPressFcn that is called is going to be the
one that belongs to the object in focus when the
key is pressed. This is probably going to be the
last object that was clicked on. Here you set the
KeyPressFcn as a property of the pushbutton but
this will only be called when the pushbutton is
the object in focus. This includes the figure
window as well. This example shows how to
implement a ke

Getting FFT peaks from data 
You can use findpeaks function from octave signal
package:
http://octave.sourceforge.net/signal/function/findpeaks.html

converting an object to line 
You are looking for the morphological skeleton of
the image.
You can find that with the function bwmorphby:
bwmorph(BW,'skel',Inf);
See Docs

Plot lines where my data is constant 
Something like this works for you?
The 2:2:10 sets the level wanted to show. If you
want to see better the 10 valued level youcan play
a bit with the axis function
subplot(121)
contour(data,2:2:10,'ShowText','on')
subplot(122)
contourf(data,2:2:10,'ShowText','on')
If you want the plot upside down you can do
contour(flipud(data))

Recursive function is only generating half the desired outputs 
Solved it
function inputArray = inputBuilder(currBuild,
allInputs, currIdx)
inputArray = [];
if currIdx <= length(allInputs)
for i = 1:length(allInputs{currIdx})
mybuild = [currBuild
allInputs{currIdx}(i)];
inputArray = [inputArray
inputBuilder(mybuild,allInputs,currIdx + 1)];
end
else
if isempty(inputArray)
inputArray = {currBuild};
else
inp

Variable error rate of SVM Classifier using KFold Cross Vaidation Matlab 
You can check wiki,
In kfold crossvalidation, the original sample
is randomly partitioned into k equal size
subsamples.
and
The k results from the folds can then be
averaged (or otherwise combined) to produce a
single estimation.
So no worries about different error rates of
randomly selecting folds.
Of course the results will be different.
However if your error rate is in wide ran

on the use and understanding of pwelch in matlab 
Your results are fine. dB can be confusing.
A linear plot will get a good view,
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L1)*T; % Time vector
y = sin(2 * pi * 50 * t); % 50Hz signal
An fft approach,
NFFT = 2^nextpow2(L); % Next power of 2 from
length of y
Y = fft(y

Matrix dimensions must agree error in Matlab? 
You are trying to multiply exp(a*5) with
sin(2*pi*f*t), elementbyelement. That's only
possible if the two vectors have the same size. In
your code, t is 1x320001, while a is 1x101.
I guess what you want is:
sr = 16000;
T = 2; % seconds duration
t = 0:(1/sr):T;
n = 1;
f = ((2^(1/12))^(n49))*440;
a = linspace(0,1,numel(t));
y = exp(a*5).*sin(2*pi*f*t);
plot(t, y);
Note that I changed the

svd of a VERY LARGE sparse matrix 
The approximate matrix decomposition into a
product of three matrices is called CUR. However
I'm not sure the matlab contains its
implementation.

MATLAB : Alphanumeric character string extraction 
Ok I'm not entirely sure about whether you need
letters all the time, but here regular expressions
would likely perform what you want.
Here is a simple example to help you get started;
in this case I use regexp to locate the numbers in
your entries.
clear
%// Create dummy entries
Case1 = 'NI000166';
Case2 = '12ABC345';
%// Put them in a cell array, like what you have.
CasesCell = {Case1;Case2

How to simply downsample a triangular mesh? 
You should downsample your data,
[x,y]=meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
trisurf(tri,x,y,z)
figure
x1 = x(1 : 2 : end,1 : 2 : end);
y1 = y(1 : 2 : end,1 : 2 : end);
z1 = z(1 : 2 : end,1 : 2 : end);
tri1 = delaunay(x1,y1);
trisurf(tri1,x1,y1,z1)
You could even use downsample function on each
data.

Convert binary image to a Gussian points 
You could try a hard cap.
Either save the locations of the white points
before the convolution or find the location of all
points > 1 and set them to 1 like this:
B(B>1) = 1

How to plot different data in parallel (in continuation of the previous one) 
You can still use hold on and plot each day
separately (if I understand your question
properly, this is what you want, separate
plotting). Simply make sure your xaxis values are
correct. So e.g. if you have one measurement value
per hour, the plot day 1:
plot(1:24,valDay1,'k')
then for day 2:
plot(25:48,valDay2,'r')
etc. This will line things up correctly. Also,
consider using a datetime

In matlab, increment different column element for every row in without using a loop 
You can do this by using the linear index to each
of the elements you want to address. Compute this
using sub2ind:
>> A = zeros(4)
A =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> B = [4 2 3 1]
B =
4 2 3 1
>> i=sub2ind(size(A),B,1:4)
i =
4 6 11 13
>> A(i) = A(i)+1
A =

MATLAB CLASSES getter and setters 
Implementation
Since your class is currently a subclass of the
default Value class, your setters need to return
the modified object:
function obj = set.name(obj,name)
end
function obj = set.age(obj,age)
end
From the documention: "If you pass [a value class]
to a function, the function must return the
modified object." And in particular: "In value
classes, methods ... that modify the object mu
