Answered
Substituting particular matrix values
t1 = X1a == 255; X1a(t1) = X1b(t1); t2 = X2a == 255; X2a(t2) = X2b(t2); or Xa = cat(3,X1a,X2a); Xb = cat(...

12 years ago | 0

Answered
How to retain only the rows of a matrix based on the unique numbers in the first column of the matrix?
[~,b] = unique(a(:,1),'first'); out1 = a(b,:); out2 = a([b(2:end)-1;size(a,1)],:); or [~,b1] = unique(a(:,1),'fi...

12 years ago | 1

Answered
how to take out specific month from data
Let the 'a' is date for first frame of your 3D matrix (eg 'prec_all_years') a = [2006,1,1]; [m,n,k] = size(prec_all_year...

12 years ago | 0

| accepted

Answered
matrix formation from two given matrix
a=[5 10 15 20]; b=[2 1 4 3]; x = cumsum(b); v = zeros(x(end),1); v(x-b+1) = 1; out = diag(a(cumsum(v)));

12 years ago | 2

Solved


Sum of diagonals elements of a matrix
Given a matrix, return the sum of all the elements across the diagonals. E.g. A = [1 2 3; 4 5 6; 7 8 9;...

12 years ago

Answered
Input cell to function
use gpa(grades{n,:}) OR use new function |gpanew.m| : function grade_pt= gpanew(incell) grades= {'a+','a', '...

12 years ago | 0

Answered
extract 4*4 matrix from 8*8
blockproc(yourimage,[8 8],@(x)x.data(1:4,1:4))

12 years ago | 1

| accepted

Answered
A way to replace a single number array to a double array.
a=[ 1 1 0 0 1 ]; out = [a, ~a]+0;

12 years ago | 0

| accepted

Answered
How to filter the rows i donot want in a matrix
blockproc(A,[2,3],@(x)max(x.data)) ADD after Valley's comment cell2mat(accumarray... (cumsum([true;diff(A(:,...

12 years ago | 0

Answered
How to make and sum up a matrix with upper diagonal direction without for-loop condition [The fastest way!]
[m,n] = size(A); B = spdiags(A,0:n-1,m,n); ADD other way [m,n] = size(A); B = zeros(size(A)); ii = reshape(fi...

12 years ago | 0

Answered
cell2mat not working when cell array of type char has numbers of different lengths
c = regexp(B,'^\d*','match'); out = str2double([c{:}]');

12 years ago | 0

| accepted

Answered
How to make up the diagonal summation without for loop and with the fastest way!
A =[ 1 7 13 2 8 14 3 9 15 4 10 16 5 11 17 ...

12 years ago | 2

| accepted

Answered
Find max and min of groups in columns of a matrix
a=[0 1;-3 3;-2 -7;0 5;4 -6;1 -2] t = [true(1,size(a,2));diff(a<0)~=0]; ir = cumsum(t); jj = max(ir); ii = bsxf...

12 years ago | 1

| accepted

Answered
Match elements of column array to first column of a matrix then append row of matrix to array
A = [219 219 219 6401 6401 6401 6401 7501 7501]; B = [206 3 4 5...

12 years ago | 0

| accepted

Answered
How to reshape a curve?
load data [~,iymax] = max(y); yx = griddedInterpolant(y(end:-1:iymax),x(end:-1:iymax),'pchip'); y0 = fminsearch(@(x)y...

12 years ago | 0

| accepted

Answered
How to construct a block diagonal combined with another block diagonal with an off diagonal?
M = {[5; 10], [2 3; 8 6],-eye(2)} ii = tril(toeplitz ([3,2,0])) v = zeros(size(i2)); for jj = 2:3 t = ii == jj...

12 years ago | 0

Answered
FInd maximum in cubic spline interpolant
*EDIT* new data x = [0.70000 0.75000 0.80000 0.85000 0.90000 0.95000 1.00000 1...

12 years ago | 0

| accepted

Answered
How to calculate the perimeter and area of a polygon?
one way p1 = points(randperm(size(points,1)),:); % Let your data ii = bsxfun(@minus,p1,mean(p1))*[1;1i]; [~,jj] =...

12 years ago | 0

Answered
how to generate matrix of size 10X10?
one way ones(10,1)*(1:10)

12 years ago | 4

Answered
command unique without sorting??
for older releases of Matlab [~,b] = unique(v,'first') a_out = v(sort(b)) or [a0,b0,c0] = unique(v,'first') [...

12 years ago | 3

Answered
How can I delete a row from a cell aray, with empty cell as first column
A(~any(cellfun(@isempty, A),2), :)

12 years ago | 2

Answered
How to minimize a function with a summation of a set of data?
x = [0 1 2 3 4 5 6 7 8 9 10]; y = [0.4505 1.0838 2.2290 3.9133 4.1524 5.8258 6.5383 7.9961 8.07820 9.4427 10.1067]; ...

12 years ago | 1

Answered
How to find indexes and intersection points and finally giving them preference.
*EDIT* f = @(x){x}; [ii,jj] = find(a & a'); z = accumarray(jj,ii,[],f); [i1,j1] = find(a); x = accumarray(i1,j1...

12 years ago | 0

| accepted

Answered
How to loop over these values?
n = numel(cursor_info); out_var = cell(n,1); for ii = 1 : n out_var{ii} = cursor_info(1,i).Position; end

12 years ago | 0

Answered
How can I convert A matrix to B matrix below?
z = diag(A); ii = 1:numel(z); B = z(bsxfun(@min,ii,ii'));

12 years ago | 0

Answered
Calculate total length of perimeter
xy=[0 0 3 0 3 3 0 3]; K = convhull(xy(:,1),xy(:,2)); out = sum(sqrt(sum(diff(xy(K,:)).^2,2)));

12 years ago | 0

Answered
Is there a function to santize a date vector?
future = datevec(addtodate(now,1e6,'sec'));

12 years ago | 1

| accepted

Answered
Using the bisection method, why is f(a) not a real integer or logical?
x = sqrt((C_ocean/C_land).^2-H^2);

12 years ago | 0

Answered
matrix operations within an array
permute(X,[2 1 3]) % transposed each frame variant with arrayfun (badly) Y = arrayfun(@(ii)X(:,:,ii)',1:size(X,3),'un'...

12 years ago | 0

Answered
How do I iterate my Newton method so that I get an array of values instead of just the last number?
function R = yourNewton(f, df, x0, tol) R = []; ff = f(x0); while abs(ff) > tol B = x0 - ff/df...

12 years ago | 0

| accepted

Load more