Answered
How to use the result from a step as an input for the next step?
[EDIT] A=rand(3,3); B=rand(3,5); Y = zeros(size(B)); n = 1; for nt=1:5 if nt > 1, n = nt - 1; end Y...

14 years ago | 0

Answered
How to "stretch" matrix
a = [1 1 2 2 0 0]; t = 1.5 k=[true,diff(a)~=0]; k2 = find(k); k3 = [k2(2:end)-1 numel(k)]; k4 = k3-k2+1; ...

14 years ago | 0

Answered
Passing function handle to another function and assigning varying number of input arguments to it
please read about <http://www.mathworks.com/help/techdoc/ref/varargin.html |varargin|>, <http://www.mathworks.com/help/techdoc/r...

14 years ago | 0

Answered
2 comparisons in find(...)
t = Sig_log(:,1:2)*[2;1]; out = find(t > 1 & t < 3)

14 years ago | 0

Answered
Concatenation
a = str2double(arrayfun(@(x)sprintf('%d',a(x,:)),(1:size(a,1))','un',0)) variant a = str2double(regexprep(cellstr(num2...

14 years ago | 0

| accepted

Answered
distance between two vertices
_Pythagorean_ d = sqrt(sum((vertex1-vertex2).^2)) |hypot()| k = vertex1-vertex2; d = hypot(hypot(k(1),k(2)),k(...

14 years ago | 1

Answered
Quickly access two arrays
A = [ 2 2 1 3 2 1]; B = [1 3]; idx = find(A==2); C(numel(A)) = false; C(idx(B)) = true;

14 years ago | 1

| accepted

Answered
matrix
m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55]; *vari...

14 years ago | 0

| accepted

Answered
Vectorization of this loop
in your case r = (1:ywidth).' - round(ywidth/2); c = (1:xwidth) - round(xwidth/2); Radius = bsxfun(@hypot,r,c); t...

14 years ago | 0

| accepted

Answered
matrix manipulation
f = fopen('test.txt'); c = textscan(f,'%f'); fclose(f); out = reshape(c{:},[],3)'

14 years ago | 0

| accepted

Answered
Random numbers
idx = [1,2,4,7,8]; out = zeros(10,1); out(idx)=rand(numel(idx),1);

14 years ago | 1

| accepted

Answered
Cell array/Character array to string
cea={'8' '_1' '9' '_3'} str = strcat(cea{:}) *or* str = [cea{:}];

14 years ago | 2

| accepted

Answered
problem having reading the IP address in sorting
a = { '172.20.113.214' '85.17.72.66' '172.20.113.214' '38.124.168.125' '46.45.178.252' '172.20.113.214' '46....

14 years ago | 0

| accepted

Answered
Replace the first value in each cell of a cell array with the value from another cell array
Dnew = arrayfun(@(x,y)reshape([y,x{:}(2:end)],size(x{:})),D,F,'un',0) *OR* Dnew = arrayfun(@(x)reshape([F(x),D{x}(2:en...

14 years ago | 0

| accepted

Answered
convert matrix in single column
yourvector = yourmatrix(:);

14 years ago | 72

| accepted

Answered
Faster method of numerical Integration?
out = cumtrapz(a,b)

14 years ago | 1

| accepted

Answered
Character array with one letter
cha='hello'; cdot = '.'; out = cdot(ones(1,numel(cha)))

14 years ago | 0

Answered
problem in read txt file
f = fopen('test.txt') c = textscan(f,'%s'); fclose(f) d = cellfun(@(x)x(2:end-1),c{1},'un',0) *EDIT* on commen...

14 years ago | 0

| accepted

Answered
Count/find/sum the number of statements to calculate percentage
eg ii = 0; for ... ... if all(abs(imag(roots) < 100*eps)) fprintf('The equation is good'); ...

14 years ago | 0

Answered
Calculate the value of x entered in function(2) using function(1). How to link the two functions ?
lower=input('Enter the lower value of the range = '); upper=input('Enter the upper value of the range = '); x = lower:up...

14 years ago | 0

Answered
Simple but elusive array question
A = [1 1 3 2 0 4 3 0 0 0 0 0] s1 = size(A); out = zeros(size(A)); t = A~=0; A1 = bsxfun(@times,t,1:s1...

14 years ago | 1

Answered
Multiple things to call into a loop
|['/',subno{p}]| instead of |'/subno{p}'|

14 years ago | 0

| accepted

Answered
Subdividing a cell array of ratings data
ID= {'ID1','01-Jan-2001','A'; 'ID1','05-Mar-2003','D'; 'ID1','15-Dec-2007','B'; 'ID1','15-Dec-2007','B'; '...

14 years ago | 0

Answered
Vectorization
A = 1000; n = 12; r = .1:.01:.2; k = (15 : 5 :25).'; t1 = bsxfun(@(r,k)(1 + r/n) .^(n*k),r,k); P1 = A*bsxfun(@times,r,t1 ...

14 years ago | 0

| accepted

Answered
permutation
nchoosek(1:4,2) *ON* _ko thant's_ answer eg: t = nchoosek(1:6,3); p = 2; A = t*[1;p;p^2]; A = reshape(A,[...

14 years ago | 0

Answered
Columnwise operation.
R_SQ_s = ones(size(R_SQ),1)*sin(theta(:).').*R_SQ; or R_SQ_s = bsxfun(@times,R_SQ,sin(theta(:).'));

14 years ago | 0

Answered
finding distance from text data for latitude/longitude and creating new column of data for distance
use function |distance| from |Mapping Toolbox| LatLon = [51.8885857 -2.159813307 51.888588 -2.159810551 51.88858751 ...

14 years ago | 1

Answered
Speed up nested for loops
c0 = conv2(B,A); c = reshape(c0(2:end-1,2:end-1)',1,[]); OR c0 = conv2(Bpad,A,'valid'); c = reshape(c0',1,[]);

14 years ago | 1

Answered
What is wrong with this
z = bsxfun(@times,Mass,bsxfun(@ge,Mass,LMT)&bsxfun(@lt,Mass,HMT)); Mass_red = z(any(z,2),:)'; *OR [EDIT]* t = bsxfu...

14 years ago | 1

Answered
Prime number or its nearest prime numbers
input |x| x = 24; solution X = [x x]; out = zeros(1,2); while 1 t = isprime(X); if all(t) ...

14 years ago | 0

| accepted

Load more