Beantwortet
How do I know when to use loops and when to use vectorization?
sprintfc('%d,%d(%d)',mat)

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
Removing components of a matrix without turning it into a vector
ii = isinf(Z); out = Z(~all(ii,2),~all(ii)); or ii = ~isinf(Z); out = reshape(Z(ii),max(sum(ii)),[]);

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
3rd dimension data from each pixel to column-wise
Let |A| - your array [80x100x27] [m,n,k] = size(A); B = reshape(permute(A,[3,1,2]),k,[]); out = B(:,all(~isnan(B)));

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
How do i reverse the order of this
indexArray = startingIndex:-1:1;

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
How do I create a loop that goes up by 5 until a certain number and then up by 3?
a = 12; b = 50; n = 31; ii = 5; while a(end) < 50 if a(end) > 31 ii = 3; end a = [...

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
Use loops and/or conditions to make even numbers of a matrix the product of their row and column
Let |A| - your array [6 x 5] B = A; for ii = 1:size(A,1) for jj = 1:size(A,2) t = B(ii,jj)/2; ...

mehr als 8 Jahre vor | 0

Beantwortet
Obtaining all zeros from rand
x = rand(1,45)

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
how i do weekly average?
Let |data| - your array [978 x 744]. For MATLAB >= R2016b (here week -> [Sun : Sat]): Time = (datetime([2017 7 1 0 0 0])...

mehr als 8 Jahre vor | 1

| akzeptiert

Beantwortet
Delete rows from matrix according to another matrix?
setdiff(A,B,'rows')

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
Store and update the size of a vector after every loop
Vector = cell2mat(reshape(permute(Mixed_Prop,[3,2,1])),[],1));

mehr als 8 Jahre vor | 1

| akzeptiert

Beantwortet
How to write a code for varying step size ?
Xb = [0, .5, 1.25, 2]; dx = [.01, .005, .0001]; x_bar = cumsum([Xb(1), repelem(dx,diff(Xb)./dx)]); >> x_bar_j = 1...

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
Loops matrix to find zero then cancel the rows relative and create a new matrix
for _"B = NEW Matrix without zero"_ A = [104.727 114.779 0 104.801 97.8394 0 105.1 102.3 0 87.6095 93.4037 0.16324...

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
How to get separate data set in a for loop
A = (0:0.01:0.8)'; x = -pi/2:0.1:pi/2; m = numel(A); q = numel(x); w=0.51; G = 5; %%%%%%%%%%%!!!!!!!!!...

mehr als 8 Jahre vor | 0

Beantwortet
How can I convert the number 1 into a date value 20150101 (yyyyMMdd)?
out = datetime([2015 01 01],'F','uuuuMMdd') + A -1 or x = datevec(datetime([2015 01 01]) + A -1); out = x(:,1:3)*[1...

mehr als 8 Jahre vor | 1

Beantwortet
Using kronecker product and elementwise multiplication
der=[2 5 ;3 4] OMEGA=kron(eye(2),der) y=[3 4] out = OMEGA.*kron(y,ones(1,2))

mehr als 8 Jahre vor | 0

Beantwortet
Find diagonal vector within matrix
Let A - your array. [m,n] = size(A); if m > n, ii = sub2ind([m,n],1:m,ceil((1:m)*n/m)); elseif m < n, ii = sub2ind([m...

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
How to get the indices of two matrix simontaneously
d = squeeze(sum(bsxfun(@minus,B,permute(A,[1,3,2])).^2)); q = d <= H; Q = bsxfun(@times,(1:size(q,1))',q); Q1 = bsxfu...

mehr als 8 Jahre vor | 0

Beantwortet
Peaks over threshold counting events
nnz(diff([0;Hs_hr(:,1)>7])); or nnz(filter([1,-1],1,(Hs_hr(:,1)>7)*2-1) == 2)

mehr als 8 Jahre vor | 0

Beantwortet
how to write a code to find the position of a smaller (m x n) matrix in a big (M X N) matrix ?
>> A = [ 102 69 101 5 82 103 96 95 120 114 120 18 107 22 87 100 35 43 ...

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
How to check whether a 2d matrix is gradually increasing in values in row direction.
B = cummax(A); A([false(1,size(A,2));diff(B)==0]) = nan;

mehr als 8 Jahre vor | 2

Beantwortet
Hey guys , How can i shift rows or columns within an array?
A([2,1],:) = A(1:2,:) or circshift(A,1)

mehr als 8 Jahre vor | 0

Beantwortet
How to create matrix in MATLAB from an array?
reshape(1:12, 3, [])

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
2D subtraction from 3D
C = A - B; or C = bsxfun(@minus,A,B);

mehr als 8 Jahre vor | 1

| akzeptiert

Beantwortet
How to get rid of repeating values inside an array
v = unique(a); b = v(histcounts(a,[v(:);v(end)+eps]) == 1); or v = unique(a); b = v(histc(a,v) == 1); or ...

mehr als 8 Jahre vor | 0

Beantwortet
How can I find the cumulative sum of a vector without using the cumsum funtion or any loops
sum(hankel([zeros(numel(A)-1,1);A(1)],A))

mehr als 8 Jahre vor | 0

Beantwortet
Getting max and min values in a day for data for 8 months
T = readtable('sample.csv'); ii = [1;diff(day(T.Var1))]; q = cumsum(ii); add = accumarray(q,(1:size(T,1))',[],@(x){[m...

mehr als 8 Jahre vor | 0

Beantwortet
Reshaping a 2D matrix into a 3D matrix (layers of square matrices) with specific order (no loop)
B = mat2cell(A,[5 5 5],[5 5 5]); C = cat(3,B{:}); out = reshape(permute(C(1,1:3,:),[3 2 1]),3,[]); or [m,n] = si...

mehr als 8 Jahre vor | 0

| akzeptiert

Beantwortet
In "nchoosek" function, how to do some of elements of matrix are the same?
>> nchoosek(A,2) ans = 6 6 6 7 6 7 6 9 6 11 6 13 ...

mehr als 8 Jahre vor | 0

Beantwortet
Can I assign values to an array in a diagonal direction from a reference point on that array?
s = size(X); [~,d(:,2)] = spdiags(rot90(X)); [~,d(:,1)] = spdiags(X); out = full(spdiags(ones(s(1),size(d,1)),d(:,1),...

mehr als 8 Jahre vor | 0

Mehr laden