Answered
Code for Base Matrix
[a,~,ii] = unique(A(:,2)); [b,~,jj] = unique(A(:,3)); out1 = accumarray([ii,jj],A(:,1),[max(ii), max(jj)],@(x){x}); ...

12 years ago | 1

| accepted

Answered
Matrix creation which identify link of vehicles
[a,~,ii] = unique(A(:,2)); [b,~,jj] = unique(A(:,3)); out1 = accumarray([ii,jj],A(:,1),[max(ii), max(jj)],@(x){x}); o...

12 years ago | 1

| accepted

Answered
griddata interpolation 3 variables, determine mid values
xf = gridedInterpolant(Z,X); yf = gridedInterpolant(Z,Y); F = @(z)[xf(z(:)), yf(z(:))]; use function F: xy = F(2...

12 years ago | 0

Answered
Convert matrix size from 1xmxn to mxn
Z = randi(250,1,3,4); % your matrix one way out = squeeze(Z)'; other out = permute(Z,[3 2 1]); or out...

12 years ago | 4

| accepted

Answered
sort elements in a cell , they are all txt file names?
out = sort(files);

12 years ago | 0

| accepted

Answered
Fast creation of vector [0 0 1 1 2 2 3 3... n n]
k = [1;1]*(0:n); out = k(:)';

12 years ago | 5

Answered
Sequencing, matrix values and calling function
A=[1 0 0;1 1 0;0 1 0], I=[1 0;0 1], F=[1 2;2 1] ii = sum(A,2); z = {I,F}; out = z(ii);

12 years ago | 0

| accepted

Answered
How can I reduce the execution time when calculating mean values within a 3 times loop?
one way d = [2010 132 150 1.52 2010 132 151 2.5 2010 132 153 3.4 2012 20 289 4.69 2013 365 1440 0.2]; sd...

12 years ago | 0

Answered
Indexing and Checking on a Diagonal
one way S = randi(200,10); a = 100; % your threshold d = diag(S); % if d(ii) >= a then d(ii) = 1; else d(ii) = -1 ...

12 years ago | 0

Answered
how can i change a position of a matrix to 1?
a = rand(10,1); a(randperm(10,3)) = 1;

12 years ago | 1

Answered
how to replace elements of a matrix in a sequence by comparing with another?
y = y(:); z = z(:); [~,b] = unique(y,'first'); c = setdiff(z,y); ii = setdiff((1:numel(y))',b); out = zeros(siz...

12 years ago | 1

Answered
How to create zeros between ones in array
B = zeros(size(A)); B([strfind([0 A],[0 1]),strfind([A 0],[1 0])]) = 1;

12 years ago | 0

Answered
sorting matrix by diagonal of submatrix
[~,ii] = sort(sum(reshape(A(repmat(eye(3),1,3)>0),3,[])),'descend'); A1 = reshape(A,3,[],3); out = reshape(A1(:,:,ii),3,...

12 years ago | 2

| accepted

Answered
Plotting a 2D matrix
s = size(M); [z,x] = ndgrid(1:s(1),1:s(2)); data = permute(num2cell(cat(3,x,M,z), 2),[3,2,1]); plot3(data{:}); or...

12 years ago | 3

| accepted

Answered
"Not enough input arguments"
function [x1,x2] = azeo(a,b) t = .35 < a; ab = b; ab(t) = a(t); m = (0.65/0.35).^(2*t-1); n...

12 years ago | 0

Answered
filling matrix instead of using for loops
A = 1:10; B = 20:29; [m,n] = ndgrid(A,B) K = [sin(m),cos(n);cos(n).*sin(m),exp(m)]; s = size(K); p = size(m...

12 years ago | 0

| accepted

Answered
extracting columns with comparison
B = A; B(1,:) = abs(B(1,:)); [a,~,c] = unique(B.','rows'); out = [accumarray(c,(1:numel(c))',[],@(x){x})';num2cell(a'...

12 years ago | 0

Answered
find column from list then save cell
C = B(:,ismember(B(1,:),A))

12 years ago | 0

| accepted

Answered
using while-end block to find pattern in an array
m = numel(pattern); ii = strfind(V(:)',pattern(:)'); k = ii(1); f = ii(2:end); count = 1; while numel(f) >= 1 ...

12 years ago | 0

Answered
matrix NaN change value
Use variant [ii,jj] = ndgrid(1:size(M1,1),1:size(M1,2)); l = ~isnan(M1); [i0,j0] = find(l); F = scatteredInterpola...

12 years ago | 0

Answered
Help writing a simple function
function out = f(x) out = sign(x-4); out(~out) = cos(4); end use >> out = f([- 3 5 6 4 -2 3 1 4]) ...

12 years ago | 0

Answered
How can I shift rows and columns, and also replicating Sub matrixes.
A = magic(4); D = circshift(A,[1,2]); B = randi(10,2); out = kron(ones(2),B);

12 years ago | 0

Answered
I have to compile the function but my matrix dimensions are not equal.
t = -10:0.1:10; w = input('enter the value of w = '); b = input('enter the value for b = '); f = cumsum(1./( 1 + ex...

12 years ago | 0

Answered
looping through symmetric matrices
T = randi(20,10); % Q = randi(20,10); % T = tril(T) + tril(T,-1)'; % Q = triu(Q) + triu(Q,1)'; ...

12 years ago | 1

Answered
How to delete a specific number from a vector, if there are duplicates after each other?
A = [1 2 3 4 5 0 4 6 5 0 0 98 0 0 1 2 23 4 0 0 0 2 5 8 0]; out = A([true;diff(A(:))~=0]); or only fo zeros in A ...

12 years ago | 0

| accepted

Answered
Comparing vectors of different size
C = A(all(bsxfun(@ge,A,B.')));

12 years ago | 1

| accepted

Answered
Nested for loop to parse specific array indices not working?
ii = [5,8]; n=10; v = zeros(1,500); v(ii(1):n:end) = 1; v(ii(2)+1:n:end) = -1; A = cumsum(v);

12 years ago | 0

Answered
how shall i keep the particular position of a column of a matrix to to repeat for all other columns?????
[~,jj] = sort(a(:),'descend'); y1 = sort(jj); y = y1(1:err);

12 years ago | 0

| accepted

Answered
Uneven data multiplication in Matlab
out = bsxfun(@rdivide,NumberOfDishes,NumberOfLocations);

12 years ago | 0

Load more