Solved


Pi Estimate 1
Estimate Pi as described in the following link: <http://www.people.virginia.edu/~teh1m/cody/Pi_estimation1.pdf>

14 years ago

Answered
Question about fractional values.
use |Symbolic Math Toolbox| x = sym('5/3'); [N,D] = numden(x); out = [N,1/D];

14 years ago | 0

Answered
extracting numbers from a string in an array
out = cellfun(@(x)str2double(regexp(x,'\d*\.\d*','match')),p);

14 years ago | 2

| accepted

Answered
Compute values in the nodes of a 3d matrix
d = cumsum(BW2(:,:,end:-1:1),3); index = bsxfun(@eq,sum(BW2,3) - 1,d(:,:,end:-1:1) - cumsum(BW2,3)); T2 = T.*index + bsx...

14 years ago | 1

| accepted

Answered
Error ??? Subscript indices must either be real positive integers or logicals.
use struct - array: out = cell2struct(num2cell(V),regexp(variables,'\w*','match'),2); or out = cell2struct(num2cell...

14 years ago | 0

Answered
Given two vectors A and B, what is the best way to generate the vector C such that sum(C==A(i)) = B(i)?
A = [1 2 3]; B = [2 4 6]; i2 = cumsum(B); idx = zeros(1,i2(end)); idx(i2 - B + 1) = 1; C = A(cumsum(idx)); ...

14 years ago | 1

| accepted

Answered
regexp: extra cell layer in the output
c = regexp(HeaderLine,'^(.*) Project Number:(.*) Sample Name:(.*) Depth: (.*)$', 'tokens'); out = c{:};

14 years ago | 0

| accepted

Answered
How can I calculate integral?
please try this is code: sigmaZ=rand(4,4); f = @(theta)1./(arrayfun(@(x)det(sigmaZ/sin(x).^2 + eye(4)),theta)); out =...

14 years ago | 0

| accepted

Answered
Compute values in the nodes of a 3d matrix
Please, try this is code: % Create the surface: x = rand(100,1)*4 - 2; y = rand(100,1)*4 - 2; S = x.*exp(-x.^2-y.^...

14 years ago | 1

| accepted

Answered
I got this Error :Matrix dimensions must agree
one way %W1: n = (1:2:401).'; t = linspace(-0.5,0.5,250); f = 4/pi*sum(bsxfun(@times,1./n,sin(2*pi*n*t))); %W2:...

14 years ago | 0

Answered
How can I convert 2-D array to 1-D array.
one way out = oprtn_pts(:); or out = oprtn_pts.'; out = out(:); other: out = reshape(oprtn_pts,[],1); ...

14 years ago | 0

| accepted

Answered
finding a minimum from multiple matricies
Let your three matrices in 3D array M M = randi(234,5,5,3); % initial array [v,ii] = min(M,[],3);

14 years ago | 1

Answered
How to store values from a loop in a matrix
M3 = cell(size(M,1),1); for ii = 1:size(M,1) X = M(ii,2); if X<60 M3{ii} = 'F...

14 years ago | 1

Answered
How can I efficiently down-sample data that is non-uniformly spaced?
[Y, M, D, H, MN] = datevec(data(:,1)); [c,c,c] = unique([Y, M, D, H, MN],'rows'); out = accumarray(c,data(:,2),[],@mean)...

14 years ago | 1

| accepted

Answered
keeping elements with specific conditions in a matrix
s = size(A); B = A(rem(s(1) - sum(A ~= 999),s(1))+1 + s(1)*(0:s(2)-1)); ADD t = A ~= 999; tt = any(t); out = ...

14 years ago | 0

| accepted

Answered
Combinations of different size columns (arrays)
a = (1:5)'; b = (4:10)'; [i2,i1] = ndgrid(b,a); out0 = [i1(:),i2(:)]; out = out0(abs(diff(out0,1,2)) > eps(100),:...

14 years ago | 1

| accepted

Answered
HOW TO GET TOTAL DATA FROM FOR LOOP?
try this ( *EDIT* ) dim=32; [kx,ky]=meshgrid(-1:2/(dim-1):1); circ=sqrt(kx.^2+ky.^2)<1; kx=kx/2; ky=ky/2; al...

14 years ago | 0

Answered
delete the rows will all zeros in multi-dimensional matrix
out = reshape(M(bsxfun(@times,any(M,2),ones(1,size(M,2)))>0),[],size(M,2),size(M,3)); or only for your example reshape...

14 years ago | 0

| accepted

Answered
How to calculate the median of a column depending on the value of another column?
B = accumarray(A(:,1),A(:,2),[],@median); out = [A, B(A(:,1))];

14 years ago | 1

| accepted

Solved


Create incremental spiral WITHOUT USING EVAL or FEVAL
Constructions that use feval or eval are used to cheat with cody. This test-suite tries to avoid that trick. The goal of this...

14 years ago

Answered
Change dimension of a matrix
reshape(yourmatrix,256,256,[]); or permute(reshape(yourmatrix,256,256,[]),[2 1 3]);

14 years ago | 0

| accepted

Answered
High frequency large time-series matrix: Split in months
data = randi(456,800,15); % 15 samples and 800 daily data for example. datainitial = '2009-07-13'; [y,m,d] = datevec(da...

14 years ago | 1

Answered
Converting data to decimal
hex2dec(reshape('123446739FBCDE',2,[])')

14 years ago | 0

| accepted

Answered
convert image into 3XN matrix
[x,y] = ndgrid(1:size(orgim,1),1:size(orgim,2)); mydata = [y(:),x(:),orgim(:)]; or mydata = [fliplr(fullfact(size(o...

14 years ago | 0

| accepted

Answered
Help with reshaping large 2D array --> 3D array -- order matters!!
A = randi(1000,84,259200); % A - initial array out = reshape(A',360,720,[]);

14 years ago | 0

Answered
this should be easy I have a while loop that is infinite
x = 1; while x(end) < 99 x=[x x(end)+2]; end

14 years ago | 0

Answered
How can i can convert A matrix to the type i want
I=[1 0 1 1 0 1 1 0 0 1 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1]; I(1:size(I,1)+1:end) = 0; or I(eye(size(I))...

14 years ago | 2

Answered
How to sort several coordinates ?
x=[3 2 1]; y=[4 5 6]; [xout,i1] = sort(x); yout = y(i1); or xy = sortrows([x;y].',1).'; yout = xy(2,:);

14 years ago | 3

| accepted

Solved


"mirror" matrix
Create n x 2n "mirror" matrix of this type: e.g. for n = 2 m = [1 2 2 1;1 2 2 1] e.g. for n = 3 m = [1 2 3 3 2 1...

14 years ago

Answered
Matlab coding to show the string in one line
out = [A{:}]; or out = cat(2,A{:}); or out = strcat(A{:});

14 years ago | 0

| accepted

Load more