Answered
adding coloum
A = [1 2 3;4 5 6] B = [7;8] C = [A,B] *_or_* C = A; C(:,end+1) = B

14 years ago | 0

Answered
How to multiply two matrices
[m n p]= size(A); o1 = ones(p,1)); out = cell2mat(cellfun(@mtimes,mat2cell(A,m,n,o1),mat2cell(B,m,n,o1),'un',0)); _*ADD*_...

14 years ago | 0

| accepted

Answered
indices and values
*[EDIT]* fid = fopen('nameyourfile.txt','r'); c = textscan(fid, '(%f,%f)%f','collectoutput',true); fclose(fid) a = acc...

14 years ago | 0

Answered
How to use textscan from the middle of a file.
_*[EDIT]*_ for the case when |nameyourfile.txt| contains data in the form: '20111006 0:00,1210,134,98,984,7.83,235,2.47' ...

14 years ago | 0

| accepted

Answered
Convolution with gabor matrix of type cell
use |cell2mat| e.g. C1 = {1:5} out1 = cell2mat(C1) C2 = arrayfun(@(x)x,1:5,'un',0) out2 = cell2mat(C2)

14 years ago | 0

Answered
regarding storage issues for mixed-type value matrix
% cell array A = {1 12345;2 'abcde'} % structure array A = struct('iter',{1 2},'ID',{12345...

14 years ago | 0

| accepted

Answered
Manipulate Matrix Element using subscripts (ex: isprime(i-j)) or (i+j)>10)
n = 10 out = bsxfun(@(x,y)isprime(abs(x-y)),1:n,(1:n)')

14 years ago | 1

Answered
???index exceeds matrix dimensions
x=1:42 c = 2*x+1 more :) c = zeros(1,42); for x = 1:42 a = x; b = a + 1; c(x) = a + b; end more 2...

14 years ago | 0

| accepted

Answered
Top Average
_*[deleted]*_ Please read about: <http://www.mathworks.com/help/techdoc/ref/function_handle.html function_handle (@)>, <http://...

14 years ago | 0

Answered
How to extract cell array in matlab
out = datevec({'22.11.2011 13:58:56.16'},'dd.mm.yyyy HH:MM:SS') out = out(end) *_OR_* out = sprintf(':%d',out(end))

15 years ago | 1

Answered
Concatenation of matrices both vertically and horizontally in a specific order.
A3d = randi(99,3,3,3) B3d = randi([100,300],3,3,3^2-3) n = eye(3) nn = ~n C(nn) = mat2cell(B3d,size(B3d,1),size(B3d,2)...

15 years ago | 1

| accepted

Answered
Matrix Solution
n = 7; k = factorial(0:n-1); out = factorial(bsxfun(@plus,1:n,(1:n)')-2)./bsxfun(@times,k,k');

15 years ago | 0

Answered
Iterating to Find the max value
muscleangle = 1:360; a=0.15; b=0.3; c=0.6; W=40; Wo=60; Fmy=(b*W+c*Wo)/a; Fm=Fmy./sind(muscleangle); F...

15 years ago | 2

Answered
Looping through 3D matrix
in your case a1 = sortrows(tride); nextvoy = permute(reshape(a1,3,3,[]),[1 3 2]); _*variant 2*_ a1 = sortrows(tride); ...

15 years ago | 0

| accepted

Answered
Sparse Matirx
A = rand(10) A(A>.15) = 0 % existing matrix Asp = sparse(A) % sparse matrix

15 years ago | 0

Answered
error CAT arguments dimensions are not consistent.
genedata=1:100; IDX = kmeans(genedata',20); genenum = cell(20,1); for i = 1:20 genenum{i} = sum(IDX == i); end ...

15 years ago | 0

| accepted

Answered
Calculating distances between coordinates from a matrix
use function |dist| from |Neural Network Toolbox| Dist = dist(Pop(:,2:3)') _*variant 2*_ with use function |pdist| from |Sta...

15 years ago | 5

Answered
How to solve 4 nonlinear equations (in 4 unknowns) ITERATIVELY
_*variant*_ a = rand(4); a(1,end) = 1; f1 = @(x)sum(bsxfun(@minus,a(:,1:end-1),reshape(x(1:end-1),1,[])).^2,2) - a(:,end)...

15 years ago | 1

| accepted

Answered
unique command
x = randi(8,15,1) a = unique(x) number_of_frequent = histc(x,a) out = [a number_of_frequent]

15 years ago | 1

| accepted

Answered
Matrix Manipulation
Z = prod(bsxfun(@times,permute(X,[1 3 2]),permute(X,[3 2 1])),3);

15 years ago | 0

Answered
mutiplying a role of number and seach or max and min value
a=1:3; b=3:5; c = a(:)*b(:).'; [~, a2] = cellfun(@(x)x(c(:)),{@min,@max}); [iout,jout] = ind2sub(size(c),a2); c_min = [a(i...

15 years ago | 0

Answered
inserting data values at correct row in a matrix using Matlab
C = [A zeros(size(A,1),1)] a = ismember(A(:,1:end-1),B(:,1:end-1),'rows') C(a,end) = B(:,end)

15 years ago | 0

Answered
I need help to convert ascii data matrices to complex data matrices
z ={{'1930+5263i<E>' '3930+5563i<E>' '1930+5263i<E>' '3930+5563i<E>'} {'1930+5263i<E>' '3930+5563i<E>' '1930+5263i<E>' '3930+5...

15 years ago | 0

Answered
Find divisors for a given number
N=8 K=1:8 D = K(rem(N,K)==0)

15 years ago | 10

| accepted

Answered
adding matrices inside a big matrix
e.g. A = randi(25,12,16); m = 4; n = 4; [M,N] = size(A); out = reshape(sum(sum(reshape(A.',n,N/n,m,[]),3)),n,[])'; *...

15 years ago | 0

Answered
Vectorized for loop
e = nonzeros(tril(bsxfun(@plus,x1,x1')+abs(bsxfun(@minus,y1,y1')),-1)); *_variant with loop_* nx = numel(x); ny = nx - 1...

15 years ago | 0

Answered
Cross Products MatLab
fa_lbf = 35 alpha_deg = 55 f_lbf = fa_lbf*[sind(alpha_deg);cosd(alpha_deg);0] r_in = [10;5;0] r_ft = r_in/12 m_lbf_f...

15 years ago | 2

| accepted

Answered
Creating a vector with duplicate points after point 1
_*variant*_ n=7; out = [1 reshape(ones(2,1)*(2:n),1,[])] _*variant 2*_ out = ones(1,2*n-1) out(2:2:end) = 2:n out(3...

15 years ago | 0

| accepted

Answered
Placing Blocks of fixed size to random positions in a bigger matrix
M = zeros(5) m = randi(4,3) sM = size(M); sm = size(m); k=sM-sm+1; iM = reshape(1:numel(M),sM(1),[]); iw =...

15 years ago | 0

| accepted

Answered
Efficient code writing...
_*variant*_ C = cat(3,x, y, z); s = size(C); Cout = permute(reshape(M*reshape(permute(C,[3 2 1]),s(3),[]),s(3),s(2),[]),[...

15 years ago | 0

| accepted

Load more