Number of 1s in a binary string
Find the number of 1s in the given binary string.
Example. If the input string is '1100101', the output is 4. If the input stri...
How close to a hole
Suppose you have a description of good places (ones) and bad places (zeros). You want to know your distance from a bad place (in...
4 years 前
已解决
Make the vector [1 2 3 4 5 6 7 8 9 10]
In MATLAB, you create a vector by enclosing the elements in square brackets like so:
x = [1 2 3 4]
Commas are optional, s...
4 years 前
已解决
Center of mass
Given a matrix M(m,n), where m is the number of vertices of the geometrical element and n is 2 or 3 (2D-plane figure or 3D-solid...
4 years 前
已解决
Energy of an object
Calculate the total mechanical energy of an object.
Total Energy= Potential energy + Kinetic energy
P.E.=m*g*h
K.E.=1/2...
Find indices of diagonal elements
Given a matrix A and a diagonal index d (where 0 indicates the main diagonal and off-diagonals are identified by positive and n...
4 years 前
已解决
Neither minima nor maxima
Input v is a vector. Return all the elements of v which are not a local minimum or maximum.
Example:
v = [1 2 3 4 5]
Ou...
4 years 前
已解决
Elements with highest local average
Input v is a row vector such that length(v)>3. Consider a sliding window of length 3 that is used to calculate the local average...
4 years 前
已解决
Hard limit function
Classify x data as
if x>=0 then y=1
if x<0 then y=0
Example
x = [ -2 -1 0 1 2]
y = [ 0 0 1 1 1]
4 years 前
已解决
Find Elements in Range
Based on a question on <http://www.mathworks.com/matlabcentral/answers/ MATLAB Answers>.
Find all the elements of a vector wh...