Answered
Finding the index of a particular point
s = n == 0 | n == 1; s = s(:)'; out = [strfind(s,[1 0 ]), strfind(s,[0 1])+1];

13 years ago | 0

Answered
Select one root of an second degree equation
p = [3 -6 -7]; r = roots(p); out = r(r>0);

13 years ago | 1

Answered
Split a vector into multiple columns by another vector.
mv = randi(120,150,1); %measurement values cv = randi([1 5],150,1);%categorical identification variable out = accum...

13 years ago | 0

Answered
Creating a frequency table
x=[1 1 2 2 1 2 ]; a = histc(x(:),0:4); out = [(0:4)', a, a/sum(a)*1e2];

13 years ago | 1

Answered
Read cell via indexing multiple times, without using for-loop
C = {'A' 'B' 'C'}; Ind = logical([ 1 0 0 1 0 0 0 0 1 0 1 0]); ii = bsxfun(@times,Ind,1:n...

13 years ago | 1

| accepted

Answered
How to find x data in a interpolate curve?
f2 = @(y)fzero(@(x)fitresult(x)-y,0); out = f2(2867.04);

13 years ago | 0

| accepted

Answered
How to match an input value with values stored in array or a file
A=[1, 3, 4, 1.5; 2, 4, 5, 1.6; 3, 5, 7, 2.2] newobjects = [ 3, 4, 4.5; 7, 7, 2.8] B = [A(:,2:end);newobjects]; [a...

13 years ago | 0

| accepted

Answered
Organize data as vector matrix and do calculation ?
[Az, El] = meshgrid(0:60:360, 0:15:90); [x, y, z] = sph2cart(Az*pi/180, El*pi/180, 1); refV2 = cat(3,-x,-y,z); lightV...

13 years ago | 0

| accepted

Answered
Vertically concatenate fields with same names from different structures
data1 = struct('x',{12 [34 56] [2 4; 6 7]},'y',{23 67 09}); data2 = struct('x',{9 [2 2 2 2 2;3 3 3 3 3] [2 4; 6 7;9 6]},'y'...

13 years ago | 1

Solved


Sum the numbers on the main diagonal
Sum the numbers on the main diagonal of an n-by-n matrix. For input: A = [1 2 4 3 6 2 2 4 7]...

13 years ago

Answered
Comparing Values from file to cell array
f = fopen('yourfile.txt'); c = textscan(f,'%s', 'delimiter', '\n'); fclose(f); c1 = regexp(c{:},'^3.*','match'); o...

13 years ago | 0

Answered
using FIND in 3D matrix
[ii,jj]=ismember(reshape(A,[],size(A,3))',B(:)','rows'); out = jj(ii);

13 years ago | 0

Answered
Extract the first negative value in a matrix column
t = A < 0; [~,jj] = find(t); out = accumarray(jj,A(t),[],@(x)x(1))';

13 years ago | 0

Answered
importing a column of data from a text file
d = dlmread('yourtxtfile.txt'); [k,k] = max(log10(d(1,:))); out = d(:,k); or [k,k] = max(log10(d(:))); out ...

13 years ago | 0

Answered
how to plot only one iteration in for loop?
id = [4 10 26 78]; % Let id case's use for the plotting. for i1 = 1:100 C = B + A(1:end,i1); if ismember(...

13 years ago | 0

Answered
Multiplying/Dividing a Column Vector with a Constant
Nr = Test_dist ./ circumf;

13 years ago | 0

| accepted

Answered
horzcat error while using ' '
names={'john'; 'ravi'; 'mary'; 'xiao'} howdy=(10:10:40)'; result = strcat(names,{' '},num2str(howdy));

13 years ago | 0

Answered
Divide an array in areas based on its values
a=[1 1 1 1 1 1 12 10 1 1 1 1 1 11 12 1 1 1 2 3 ]; a1 = a == 1; ii = [true, diff(a1)~=0]; idx = cumsum(ii); out = a...

13 years ago | 0

Solved


Procrustean bed
Given a vector x and an integer n, convert x to a vector of length n by (1) chopping off the end if it is too long, or (2) addin...

13 years ago

Answered
Convert xy Coordinates to Matrix
after John's comment in Image Analyst's answer: out = accumarray([x(:),y(:)],z(:),[10 10]); or out = zeros(10); ...

13 years ago | 2

| accepted

Answered
A simple regex error
use tokens=regexp(str1,'peak\s*memory\s*use(\s)*d')

13 years ago | 0

| accepted

Answered
How to do a group by in matlab
[i1,i2] = ismember(data(:,1),lookfor); d2 = data(i1,2:end); [j1,j2] = ndgrid(i2(i1),1:size(d2,2)); anwser = [lookfor,...

13 years ago | 0

Solved


Put m balls into n boxes (again)
According to <http://www.mathworks.com/matlabcentral/cody/problems/1516-put-m-balls-into-n-boxes Cody Problem 1516>, if I put 3 ...

13 years ago

Solved


Change the sign
Given a matrix x, return one with each diagonal element replaced by its absolute value, and each off-diagonal element replaced b...

13 years ago

Solved


Geometry: Find Circle given 3 Non-Colinear Points
*This Challenge is to determine the center and radius of a circle given three non-colinear points.* *Input:* Points *Outpu...

13 years ago

Solved


Put m balls into n boxes
Can you find all the cases where, if I put 3 balls into 2 boxes the case is 1 1 1 1 1 2 1...

13 years ago

Solved


Frobenius Norm
Write your own version of Frobenius Norm without using the 'norm' function.

13 years ago

Answered
geometric mean month by month
out = accumarray(B(:,2),B(:,1),[],@geomean); ADD if the second column of your data is the same as: b = arrayfun(@(x...

13 years ago | 0

Answered
NCHOOSEK - What am I doing wrong?
A = num2cell(V,2);

13 years ago | 1

Answered
Fast average calculation of submatrices in large matrix
PART 1 use function |blockproc| from |Image Processing Toolbox| a1 = blockproc(M,[4,4],@(x)mean2(x.data)) or without ...

13 years ago | 1

| accepted

Load more