Risposto
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...

oltre 4 anni fa | 0

| accettato

Risposto
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);...

oltre 4 anni fa | 0

| accettato

Risposto
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 ...

oltre 4 anni fa | 1

Risposto
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...

oltre 4 anni fa | 1

Risposto
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=...

oltre 4 anni fa | 0

| accettato

Risposto
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,...

oltre 4 anni fa | 2

Risposto
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

oltre 4 anni fa | 0

| accettato

Risposto
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')

oltre 4 anni fa | 0

| accettato

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

oltre 4 anni fa | 1

| accettato

Risposto
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. ...

oltre 4 anni fa | 0

| accettato

Risposto
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" "...

oltre 4 anni fa | 0

| accettato

Risposto
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('...

oltre 4 anni fa | 0

| accettato

Risposto
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(:)'

oltre 4 anni fa | 0

| accettato

Risposto
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;

oltre 4 anni fa | 0

| accettato

Risposto
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...

oltre 4 anni fa | 0

Risposto
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 ...

oltre 4 anni fa | 0

Risposto
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]...

oltre 4 anni fa | 0

| accettato

Risposto
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)); ...

oltre 4 anni fa | 1

| accettato

Risposto
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)

oltre 4 anni fa | 0

Risposto
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...

oltre 4 anni fa | 0

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

oltre 4 anni fa | 1

Risposto
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 =...

oltre 4 anni fa | 0

Risposto
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...

oltre 4 anni fa | 1

| accettato

Domanda


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 ...

oltre 4 anni fa | 1 risposta | 0

1

risposta

Domanda


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...

oltre 4 anni fa | 1 risposta | 0

1

risposta

Risposto
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].*...

oltre 4 anni fa | 0

| accettato

Risposto
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...

oltre 4 anni fa | 3

Risposto
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...

oltre 4 anni fa | 1

| accettato

Risposto
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)

oltre 4 anni fa | 0

Risposto
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)...

oltre 4 anni fa | 0

| accettato

Carica altro