Answered
I have array and want to calculate mean every five element in this array and replace every five element by their mean value
A = 1:100 n = 5; Astair = repelem(mean(reshape(A,n,[]),1),1,n) plot(A) hold on plot(Astair)

3 years ago | 0

Answered
svd(X,"econ") does not work as expected if X is square nxn matrix with rank<n
You should read the doc again: "[___] = svd(A,"econ") produces an economy-size decomposition of A using either o...

3 years ago | 0

Answered
speed up for loop execution
Try this: T = reshape(temp2m_all_grids_avg, [], 1, 1); Tc = reshape(temp2m_all_grids_C_avg, [], 1, 1); hbins = reshape(elev_b...

3 years ago | 0

| accepted

Answered
Sum: every nth column and groups/blocks of columns
c=3; % no. of countries s=4; % no. of sectors X=magic(c*s); % 12 XX = reshape(X,size(X,1),s,[]); S = sum(XX,3) C = squeez...

3 years ago | 2

| accepted

Answered
slope of non linear
One of the most robust estimation of slope (in 2D) is using SVD % Fake data x = 10*rand(1,19); y = 2 + 3*x; x = x + 0.1*rand...

3 years ago | 0

Answered
How to use scatteredInterpolant in case of dimensions more than 3
Here is a linear scattered interpolation in any-dimension. It's bare calculation for a single query point, up to you to adapt f...

3 years ago | 0

| accepted

Answered
How to transpose many matrices X_1 ... X_N at once?
This is the solution for the endless issues you are and will be enountered due of your naming variable with counter X_1 = rand(...

3 years ago | 1

Answered
array n x 3^n with all possible combinations of 0, 1 and -1
n=3; c=cell(1,n); [c{:}]=ndgrid(-1:1); c=reshape(cat(n+1,c{:}),[],n).'

3 years ago | 1

| accepted

Answered
How to determine if matrix elements are incremented on a regular interval?
"timeStamp(m) + 0.2 == timeStamp(m+1)" You should never compare floating points with "==" rather threshold = 1e-10; if abs(t...

3 years ago | 0

| accepted

Answered
GUI callback interrupts timer callback causing deadlock
Checkout parfeval that can be used run both tasks in parallel (I would put the log in background)

3 years ago | 0

Answered
How can I Perform bitxor operation in matrix?
A=[1 2 3 4], B=[11 22 33 44;3 4 5 6], C=zeros(max(size(A),size(B))) C(:,1:2:end)=bitxor(A(:,1:2:end),B(:,2:2:end)); C(:,2:2...

3 years ago | 1

| accepted

Answered
Parfor loop classification "fix usage of indicated variable" error
Your code is good to be called "spagetti". If all the image have the same size, you must tell parfor what they are: jValues=1:2...

3 years ago | 0

Answered
How to generate a binary matrix with a fixed sum in rows and a changeable sum in columns?
A=kron(eye(5),ones(3,1)); A=A(randperm(end),randperm(end)) sum(A,1) sum(A,2)

3 years ago | 0

Answered
fminunc Converging at a strange point
@zhou caiwei "1. MATLAB has a variety of solutions, if one of them not work, try others until the prolem is solved; 2.MATLAB is...

3 years ago | 0

| accepted

Answered
How can I get specified elements of matrix?
a(1:10:end)

3 years ago | 0

Answered
How do I modify/add data to a struct along specific field string values?
Try this: func = @(x) STR(x).numbers - STR([STR.type] == "other fruits").numbers isfruit = contains([STR.type], "fruits"); ne...

3 years ago | 0

| accepted

Answered
Number of unique coordinates in an array
Is this what you want? n=4; d=3; c=cell(1,d); [c{:}]=ndgrid(1:n); relvnt=reshape(cat(d+1,c{:}),[],d); dm = d-sum(diff(sor...

3 years ago | 0

| accepted

Answered
Nesting depth and the error "Expected one output from a curly brace or dot indexing expression, but there were x results."
a work around if you insist on oneline a(1).x.y=1 a(2).x.y=2 axy = [struct([a.x]).y]

3 years ago | 1

| accepted

Answered
How to perform repmat function to repeat rows of a matrix
n = 2; kron(A,ones(n,1))

3 years ago | 0

Answered
How to perform repmat function to repeat rows of a matrix
n = 2; A(kron(1:end,ones(1,n)),:)

3 years ago | 0

Answered
How to perform repmat function to repeat rows of a matrix
n = 2; A(ceil((1:n*end)/n),:)

3 years ago | 0

Answered
How to perform repmat function to repeat rows of a matrix
A=[1,0,0,0,1;2,0,0,0,2;3,0,0,0,3] A(repmat(1:end,2,1),:)

3 years ago | 0

| accepted

Answered
How to perform repmat function to repeat rows of a matrix
A=[1,0,0,0,1;2,0,0,0,2;3,0,0,0,3] reshape(repmat(reshape(A,1,1,[]),2,1,1),[],size(A,2))

3 years ago | 0

Answered
parfor and rng(1)
rdn(1) outside the parfor has no effect. from the doc: "For independent streams on the workers, use the default behavior or co...

3 years ago | 0

| accepted

Answered
Problems in running for loop on keys on container maps
keySet = {'1,1', '1,2', '1,3'}; %use cell array valueSet = {[2 3], [3 4], [9,6]}; M = containers.Map(keySet,valueSet); for p...

3 years ago | 0

| accepted

Answered
Parfor loop classification "fix usage of indicated variable" error
LEDdetectThresh=(mean(C_data_ArrayMean(:,:,idx),1))+C_data_ArrayStd(:,:,idx); LEDdurIndx=find(C_data_ArrayMean(:,:,idx)>LEDde...

3 years ago | 0

Answered
Vectorizing or otherwise accelerating nested loops with large multidimensional arrays
% Generate dummy data B=randi(4,10,3,5); A=rand(10,3,5); meanAmp = nan([max(B,[],'all'),size(A,2),size(A,3),size(A,3)]); f...

3 years ago | 0

Question


Why TMW does not improve INV?
If TMW thinks the legacy algorithm behind INV applied on full square matrix (base on LU and LDT) is not accurate enough (*), why...

3 years ago | 1 answer | 0

1

answer

Answered
Modify off diagonal elements of Matrix without looping
M = 4; A = rand(M); A(1:size(A,1)+1:end) = 10, % This is how you change the diagonal of A using linear indexing

3 years ago | 0

Answered
Sharing Variables between app and matlab workspace?
Put this statement after you generate your data in the callback mydata = ... assignin('base', 'mydata')

3 years ago | 0

| accepted

Load more