Answered
How do I add a matrix to another matrix with different sizes?
EDIT [ii,jj] = ismember(B(:,1:2),A(:,1:2),'rows'); C = B; C(ii,3) = A(jj(ii),3);

13 years ago | 0

| accepted

Answered
How do I add two columns to a matrix in ascending order?
[ii,jj] = ndgrid(y,x); out = [jj(:), ii(:)];

13 years ago | 0

Answered
all possible *UNIQUE* permutations of a binary vector
c = [0 1]; cc = c(fullfact([2 2 2 2])); out = cc(sum(cc,2) == 2,:); ADD: use Roger Stafford's idea from <http://www.m...

13 years ago | 1

| accepted

Answered
How can I use different array names in a loop?
n = sprintf('a_%d_b,',1:4); a_b = eval(['{',n(1:end-1),'}']); a_b = cellfun(@(x)[x(:,1) + 7,x(:,2:end)],a_b,'un',0);

13 years ago | 0

Answered
Picking values from n-d array along 3rd dimension
[ii,jj] = ndgrid(1:m,1:n); ijk = sub2ind(size(A),ii,jj,B); C = A(ijk);

13 years ago | 0

| accepted

Answered
How do I average rows which contain the same first to elements?
[~,~,c] = unique(A(:,1:2),'rows'); out = accumarray([repmat(c,size(A,2),1) kron((1:size(A,2))',... ...

13 years ago | 1

Answered
Numerical integration with constant parameters
f = @(thea,phia,a,b,c)sin(thea)*dot([sin(thea)*cos(phia) sin(thea)*sin(phia) cos(thea)],[a*cos(thea) b*sin(thea) c*sin(thea)*c...

13 years ago | 0

Answered
How to generate a matrix whose rows numbers are not elements of a given row vector
out = A(setdiff(1:size(A,1),v),:);

13 years ago | 0

Answered
Counting numbers in a sequence while corrosponding to another sequence
A=[1 2 3 4 5 6 8 9 10 11 12 13 14]; B=[6 6 6 6 4 4 4 2 2 6 6 4 4]; t = [true;diff(B(:))~=0]; out = [B(t).',accuma...

13 years ago | 0

Answered
vectorization of ismember function
M = cell2mat(arrayfun(@(ii)ismember(A,B(ii,:)),(1:size(B,1))','un',0)); or [~,b] = ismember(B,A); M = accumarray([r...

13 years ago | 0

| accepted

Answered
Identify the mode in each column and eliminate them
reshape(a(ismember(a,[1,3])),[],size(a,2)); or hankel([1 1 3],[3 3 3]); ADD s = size(a); b = ones(s); id...

13 years ago | 0

| accepted

Answered
I got error, dimesion mismatch, what does this mean? please help
Use |cell| array: A = cell(10,10) A{1,1} = 'Story' A{1,2} = 'Force' A{2,1} = 1 A{3,1} = 3 A(2:10,2) = num2ce...

13 years ago | 0

| accepted

Answered
Unique Values based on 2 Variables
[a,b] = ismember(var2(:,1),var1); out = [num2cell(var1), accumarray(b(a),var2(:,2),[],@(x){unique(x)})];

13 years ago | 1

| accepted

Answered
find a row with -1
blnOut = find(all(ismember(A,[0,-1]),2));

13 years ago | 0

| accepted

Answered
How to find second largest value in an array?
[ii,ii] = sort(A); out = A(ii([2,end-1])); for your example (A) just: out = A([2,end-1]); more variant A1 =...

13 years ago | 4

| accepted

Answered
explicit integral could not be found for the double integral below
syms x y alpha a b xm = sin(pi*x/a); xm3 = diff(xm,3); yn =sin(pi*y/b); fun1 = matlabFunction( 6*alpha*xm3...

13 years ago | 0

| accepted

Answered
create sub arrays from a array
a=[4,4,4,3.5,3,3.1,3.2,4,3.5]; out = accumarray(cumsum([true; diff(a(:) > 3.4)~=0]),a(:),[],@(x){x});

13 years ago | 0

Answered
how to find the lowest pixel in a 3d matrix?
A = rand(15,5,5) < .3; % your data s = size(A); B = reshape(A,s(1),[]); [ii jj] = find(B); maxl = ii == m...

13 years ago | 0

Answered
extracting data from the matrix
A = randi(20,20,6); A([1 3 6],1:2) = A([2 4 9],1:2)+3*eps; x = A([1 3 7 17],1:2); [a b] = find(all(abs(bsxfun...

13 years ago | 0

| accepted

Answered
How can I save the values obtain from a for loop in a nx1 vector?
avd = conv2(datarng(:,1),[1;1;1;1]/4,'valid');

13 years ago | 0

| accepted

Answered
How to shuffle an array?
reshape([a;b],1,[]); or out = zeros(1,numel(a)*2); out(1:2:end) = a; out(2:2:end) = b;

13 years ago | 2

| accepted

Answered
Different commands for strutures and "regular" matrices
out = arrayfun(@(x)gjG(x).Data(11,:),(1:numel(gjG))','un',0);

13 years ago | 0

Answered
create a new array without nan
A - your array c = accumarray(any(isnan(A),2) + 1, (1:size(A,1))',[],@(x){x}); out = cellfun(@(x)A(x,:),c,'un',0);

13 years ago | 0

Answered
MATLAB - Solve for x --> Explicit solution cannot be found.
b = -0.9280; c = -0.5596; const = num2cell(1:6); [a,d,E,f,g,h] = const{:}; syms x out = solve(d*g*x^(2*b) +...

13 years ago | 0

| accepted

Answered
how to save the values
latent = zeros(7,400); for loop=1:7 figname=strcat(sprintf('CLL (%d).png',loop)); img=double(imread(figname...

13 years ago | 0

| accepted

Answered
indexing diagonal elements of a matrix in a loop
ii = find(diag(A)); out = A(ii,ii);

13 years ago | 1

Answered
Put a small matrix in a bigger one.
Use function |padarray| from |Image Processing Toolbox| A(padarray(true(size(B)),size(A)-size(B),'pre')) = B; or A(...

13 years ago | 3

Answered
store repetitive data results
r = 100; th = 0:5:180; c = -5*r^2+2*r^2*sind(thet).^2+2*r^2*((4-5*sind(th).^2+sind(th).^4).^(1/2)); x = cell(numel(th...

13 years ago | 0

| accepted

Answered
Integrating over integral error "A and B must be floating point scalars."
Try func1 = @(x) x + 2; func2 = @(y) integral(func1,0,y); a = integral(func2,0,1,'ArrayValued',true);

13 years ago | 2

| accepted

Answered
Replacing matrix A with another matrix that counts entries from matrix B
[ii,jj] = ismember(B,A); out = reshape(accumarray(jj(ii),1),size(A));

13 years ago | 0

Load more