Answered
Do I need to initiate the parallel computing toolbox for my code to run on multiple cores?
MATLAB has many low level functions are multi-thread coded and potentially use all the CPU core. In this case parallel tbx wil...

4 years ago | 0

| accepted

Answered
Speeding up to find minimum value using min() function
Alternative way % Fake data c=cumsum(rand(1,10000)); s=c(end)*rand(1,10000); cpad = [-Inf c Inf]; b = discretize(s,cpad);...

4 years ago | 0

| accepted

Answered
Can we compute the graph Laplacian matrix for a directed graph?
In this thread I give formula for graph, for digraph you just need to be careful about indegree or outdegree % TMW example s ...

4 years ago | 1

Answered
Which solver should I use to solve a square and symmetric, linear system of equations?
Don't worry, MATLAB backslash detects automatically the type of your matrix and adapt the method. See "Algorithm" of doc page h...

4 years ago | 1

Answered
How can the following code be optimized / vectorized?
It takes about 25 seconds only PC Ac35 = A(:,3:5); Ai = reshape(Ac35,[],1,3); B = zeros(SitesInSystem,SitesInSystem); for j=...

4 years ago | 0

| accepted

Answered
How to extract the coordinates of points/vertices in a curve?
clear MeshSize = 0.04; LensStr = 'osci'; radius = 1; %% n = ceil(radius/MeshSize); % radial resolution [X,...

4 years ago | 2

Answered
How to generate a matrix with entries of -1 and +1 of size N x M where all the columns are unique ?
N = 3; M = 5; A = (dec2bin(randperm(2^N,M)-1,N)-'0')'*2-1

4 years ago | 0

| accepted

Answered
Obtain the sorted index vector
Use the second output of sort x=[0.5; 0.4; 0.6; 0.9] [y,z] = sort(x,'descend')

4 years ago | 0

| accepted

Answered
Reversing a vector in the same line of code
a_vec = [2, 4, -5, 7, 18, 0] flip(a_vec)

4 years ago | 1

| accepted

Answered
what is the efficient way to search for value in a large struct
You structure array seems to be linear, I would store the data in a structure of (cell) arrays rather than array of structures. ...

4 years ago | 0

| accepted

Answered
About "ismember" function
No loop or arrayfun is needed Var1=["AAA" "AA" "A" "BBB" "BB" "B"]'; Var2=[1 2 3 5 7 13]'; PD=table(Var1,Var2) Var1=["B" "...

4 years ago | 0

| accepted

Answered
I have many structs (from an XML file) with some common and different fields. How can I add the missing fields to each struct automatically so that all have the same fields?
I don't read you description, just to post here my tool catstruct s1=struct('a',1,'b',2); s2=struct('b',3,'c',4); s3=struct('...

4 years ago | 0

| accepted

Answered
Generate a series of random integers but with consecutive numbers including
A=ones(4,6); A(1,:)=ceil(10*rand(1,size(A,2))); R=reshape(cumsum(A(:)'),size(A)); R=R(:,randperm(end)); R=R(:)'

4 years ago | 0

| accepted

Answered
Can this for loop be vectorized?
e_i_h_reshape = reshape(e_i_h,N_i,1,N_draws); alpha_i_h_t = e_i_h_reshape + e_h * t;

4 years ago | 0

| accepted

Answered
Why trust-region-reflective algorithm in fmincon require a gradient as input?
I don't think Matt's answer is correct, rather Torsen answer is better. The Trust region algorithm must approximate the objectiv...

4 years ago | 0

Answered
Nearest Neighbor Matching without Replacement
If you have R2019a release x=rand(1,10) y=rand(1,10) C=abs(x(:)-y(:).'); M = matchpairs(C,max(C(:))); px = M(:,1); xm ...

4 years ago | 0

Answered
Obtaining half-spaces from the convex hull in MATLAB
% k = convhull(P), the half spaces form is {x such that A*x <= b} with W=P(k,:); V=W(1:end-1,:); A=(W(2:end,:)-V)*[0 -1; 1 0]...

4 years ago | 0

| accepted

Answered
How can I sort intersections points given from polyxpoly according to order of appearence?
Some modifications based on this FEX x = cumsum(rand(1,10)); % Generate random P1 and P2 x = x/max(x); y = rand(size(x)); ...

4 years ago | 1

| accepted

Answered
How do I find if the three arrays of unequal size have the same values?
Use FEX mintersect i1 = [1 3 4]; i2 = [4 4 2 5]; i3 = [5 4 1 5 3 3 2]; mintersect(i1, i2, i3)

4 years ago | 0

Answered
Generating n bit random numbers with each bit sampled N times.
n=8; % number of bits r=10; % number of bit repetitions, 100 in your case m=20; % number of sequenes (>=r) i=zeros(r,n); for...

4 years ago | 0

Answered
Solving constrained optimization problem
A=randn(6,2) [h,lambdamin] = svds(A.',1,'smallest')

4 years ago | 1

Answered
Matlab order of operators
"`C\D'` should be equal to finding the `x` s.t. `C=(D')*x`." No. Rather D' = C*x Your code should be while true C =...

4 years ago | 0

Answered
How does 'unique' work under the hood (in general terms)
If I have to implement unique, I would implemented by sorting the find the difference similar to this a=randi(10,1,100); % u i...

4 years ago | 1

| accepted

Question


sum on empty arrays
Can someone explain the logic of third statement (Run under R2021b) : sum(zeros(0,0)) sum(zeros(1,0)) sum(zeros(2,0)) % This ...

4 years ago | 1 answer | 0

1

answer

Question


Tiff class: Tile setting
I'm confused in setting two parameters TileLength and TileWidth for Tiff object when my data is an 3D array (m x n x p). In the...

4 years ago | 1 answer | 0

1

answer

Answered
Vectorizing loop containing multiplication of a scalar and a matrix
w = [0.2,0.5,1,0.5,0.2]; i=reshape(1:length(w),1,1,[]); z = zeros(size(i)); s=sum([i-1, i, 0+z; i, i+1, 0+z; 0+z, 0+z, 1+z].*...

4 years ago | 0

| accepted

Answered
mldivide (backslash): advantage by using sparse matrix instead of a full matrix with respect to the quality of the results?
If your condition is 3.65e27 you wi=on't get any reliable solution regardless the method. The full matrix use QR with permutati...

4 years ago | 3

Answered
histc vs. histcouns
The result differ by the way the last bin is handed in both function. To get the same result you must change the last edge to In...

4 years ago | 1

| accepted

Answered
2×2 matrix
c=cell(2*2,1); [c{:}]=ndgrid(1:8); a=reshape(cat(5,c{:}),[],2,2); a=permute(a,[2 3 1]); disp(a)

4 years ago | 0

Answered
Cholesky factorization: How to change code to produce A = L' * D * L instead of A = L * D * L' .
% Generate random symetric A A=randn(5); A=A'+A; disp(A) [L,D]=ldl(A); disp(L*D*L') [L,D]=ldl(rot90(A,2)); L=rot90(L,2)...

4 years ago | 0

| accepted

Load more