Answered
Special matrix without for loop (vectorizing loop)
variant 1 B = hankel(A(1:4),A(4:end)) variant 2 B1 = cumsum([A(1:4) ones(4,3)],2) variant 3 B2 = bsxfun(@plus,A(1:4),[...

15 years ago | 1

| accepted

Answered
how to get the result as a vector
result = -q(1)-(1:2:q(1)*2)*(log(normcdf(Z,0,1))+log(1-normcdf(Z(q(1):-1:1,:),0,1)))/q(1)

15 years ago | 0

Answered
Removing certain Rows from a matrix
Hi friends! My variant n = reshape(permute(reshape(m,size(m,1),[],2),[1 3 2]),[],2); out = n(any(n,2),:);

15 years ago | 0

Answered
how can a loop be done?
for j1 = 1:size(X,2) newMatrix = X(:,1:j1); % result = fun(newMatrix) end

15 years ago | 0

Answered
doubt on using blkproc functiom
variant B=blkproc(final2,[30 height],@(x)sum(x(~isnan(x)))); OR B=blockproc(final2,[30 height],@(block_struct)sum(block_s...

15 years ago | 0

Answered
Loop unrolling question
variant npoints = 1024; w = 1; fs = 55000; t = (0:npoints-1)'/fs; p1 = t*w/fs*(1:ncls); A = [ones(npoints,1) reshap...

15 years ago | 0

Answered
filling nans between two values
A=[ 1 nan;nan 3;nan 2;4 nan;nan nan] A(A==0)=inf; A0 = A; A0(isnan(A0)) = 0; n0 = A0~=0; A1 = A0(n0); idn = cumsum(n0); idn(id...

15 years ago | 2

| accepted

Answered
How to reshape rows into columns
A =[1, 5,0,0; 2,4,0,0; 3, 2,6,4] [i1 j1] = find(A(:,2:end)) sz = size(A) out = sortrows([A(i1,1) A(sz(1)+sub2ind(sz- [0 1],i1...

15 years ago | 0

| accepted

Answered
degrees to radians
angleInDegMinSec = [123 43 15] angleInDegrees = angleInDegMinSec*[1;[1;1/60]/60] sind(angleInDegrees) % sin cosd(angleIn...

15 years ago | 0

Answered
Dimension error in matrix manipulation
variant 1 (use 'arrayfun') t = [true;diff(looktime2(:,1))~=0]; idx = [0;looktime2(1:end-1,2)]; idx(t)=1; idx2 = [idx lo...

15 years ago | 0

| accepted

Answered
matching the count of indices of two arrays
Hi Daniel! This is what you want? n = min(numel(A),numel(B)); idxequal = find(A(1:n)==B(1:n));

15 years ago | 0

| accepted

Answered
How to write several results in the same sheet of a Xls file ?
A=randi(4,3),B=randi(5,4,6),C=randi(7,3,8),D=randi(70,4,3) Am = {A B C D} N = cumsum([1 cellfun('size',Am(1:end-1),1)+1]...

15 years ago | 0

Answered
How to add some symbols into a matrix ?
X(tril(true(size(X)),-1))=nan add X(bsxfun(@lt,1:4,(1:4)'))=nan more only for cell array Xc = num2cell(X) Xc(bsxfun...

15 years ago | 1

Answered
Matlab - compare Cell-Array rows with mixed content
A = cellfun(@num2str,A,'un',0); B = cellfun(@num2str,B,'un',0); out = arrayfun(@(i1)all(ismember(A(i1,:),B)),(1:size(A,1))...

15 years ago | 3

| accepted

Answered
how to calculat the sum of pixel vaules inside a particular region
variant 1 final2 = randi([2 25],5,25); b = 5; [width, height] = size(final2); sum1 = squeeze(sum(reshape(final2,width,b...

15 years ago | 0

Answered
Rearranging an array by collecting values
variant c = accumarray(F(:,1),F(:,2),[],@(x){x}); cw = c(~cellfun('isempty',c)) cl = cellfun('length',cw); n = numel(cw...

15 years ago | 1

| accepted

Answered
accelerate filter loop
goodlines = find(abs(diff(depthAlpha(:)))<3)

15 years ago | 0

| accepted

Answered
integrate function
variant x = ...; Kt = ...; i = ...; quad(@(u)exp(-(u.^2)).*frustration_function2(u,x,Kt,i), 1e-4,1e4)

15 years ago | 0

Answered
sparse matrix
blkdiag(speye(30886,30886),sparse(68709-30886,130478-30886));

15 years ago | 1

| accepted

Answered
Indexing way to look for specifc cell arrays in a cell array of cell arrays?
R = all(reshape(ismember([A{:}],[B{:}]),[],numel(A))) _OR_ R = all(reshape(strcmp([A{:}],[B{:}]),[],numel(A))) *ADD* ...

15 years ago | 0

Answered
Switching functions smartly, like hash map
switch p case a, fu = @function1; case b, fu = @function2; case c, fu = @function3; otherwise fu...

15 years ago | 2

Answered
switch between subfunctions
use |switch| or |if..end|, e.g.: function funmain(..., p1) function funs1() ... end function funs2() ...

15 years ago | 0

| accepted

Answered
Max and Min values within vectors in a cell matrix
variant N = size(C,1); out = zeros(N,2); for i1 = 1:N p1 = [C{i1,:,:}]; out(i1,:) = [min(p1) max(p1)]; ...

15 years ago | 1

| accepted

Answered
find the Unique Coupled-value in a vector and eliminate the zero-coupled values
[a b c] =unique(vect','rows','first') out = sortrows([a,b],3) res = out(any(out(:,1:2),2),1:2)'

15 years ago | 1

| accepted

Answered
my matlab is busy!!
It solution in MATLAB with Maple Toolbox for MATLAB >> [R2,x]=solve('((1-R2)/(1-R1)*R1-(c/b*R2))*x^2+(1-R2)/(1-R1)-c/b=0'...

15 years ago | 0

Answered
Substatuting numbers in dsolve
variant syms R1 R2 C L Vc0 iL0 V = dsolve('D2x + (1/L*C)*(L/R2+R1*C)*Dx + (1/L*C)*((R1+R2)/R2)*x = 0','Dx(0) = iL0/C-Vc0/(...

15 years ago | 0

Answered
arrayfun_Apply function to each element of array
please read doc arrayfun in it case can be replaced by loop hold on for i1 = 1:size(Num,1) plot3(Num(i1,k(...

15 years ago | 0

Answered
Connecting line
added after your code hold on k = reshape([3 2 1 5 6 4],3,[]); arrayfun(@(i1)plot3(Num(i1,k(1,:)),Num(i1,k(2,:)),Num(i1,k...

15 years ago | 0

| accepted

Answered
expression substitution
char(subs('A = ABC*g + ZI/A - (CAD + EEA*d)*(g - 1)','A','A_subs')) _*ADD MORE variant*_ str='A=g*ABC+(1-g)*(CAD+d*EEA)+ZI...

15 years ago | 0

Answered
How to get symbolic subexpressions
syms u1 u2 z = vpa(u1*(2.794181081*u2^2 - 2.3381963*u2^4 + 0.46413*u2 - 0.5202912702) - 2.636996736*u2 + 0.3739*u1^4,10); ...

15 years ago | 0

| accepted

Load more