Answered
Comparing values in an array to a range
a = rand(20,20)*5; edges = [.5,1,1.1,1.6]; ii = discretize(a,edges);% [~,ii] = histc(a,edges) - if MATLAB older then R...

9 years ago | 0

| accepted

Answered
How to rewrite matrix ‘Y’ as matrix ‘A’?
*EDIT* [m,n] = size(Y); nn = 1:n; i0 = triu(nn'*ones(1,n)); i0 = i0(i0 > 0).'; ic = mat2cell(ones(size(i0)),1,n...

9 years ago | 1

Answered
Find Median of the second column when first column is Date
if your MATLAB older than R2015b [n,tt] = xlsread('2008 Data (find daily Median).xlsx'); [y,m,d] = datevec(n(:,1)); ...

9 years ago | 2

Answered
All combination for a cell structure?
I correctly understand: out = cellfun(@(x)a(:).'*a(:),numcell);

9 years ago | 2

| accepted

Answered
Generate random number between a given sequence using rand and exisiting matrix
a = 2.5e-8; b = 8e-4; my_needed_matrix = rand(size(my_existing_matrix))*(b - a)+a; Please read MATLAB Documentati...

9 years ago | 0

Answered
how to find the maximum value of a vector and ignore the error maximum?
one variant for your case: y = [1 2 3 4 5 6 100 4 3 2 1 ]; tol = 10; t = dif...

9 years ago | 0

Answered
How to apply numerical integration on a symbolic matrix?
Please try this is code: fun = {@(x,y)x+y,@(x,y)x.^2+y.^2;@(x,y)x-y,@(x,y)x.^2-y.^2} q = cellfun(@(z)integral2(z,0,1...

9 years ago | 2

| accepted

Answered
how can i genaralise this code for any m*n matrix?{the original question is to sum all the elements in the perimeter of a given matrix}?
a = randi(9,3,5) s = size(a); t = true(s); t(2:end-1,2:end-1) = false(s-2); out = sum(a(t));

9 years ago | 1

Answered
Putting 1 around the matrix
Let A - your matrix [3 x 3]: A = magic(3); out = ones(2 + size(A)); out(2:end-1,2:end-1) = A;

9 years ago | 1

| accepted

Answered
Indexing a matrix with another matrix?
[m,n] = size(Idx); [ii,~] = ndgrid(1:m,1:n); % or ii = repmat((1:m)',1,n); % ii = (1:m)'*on...

9 years ago | 1

| accepted

Answered
All combinations of matrix elements?
b = a(:)*a(:).'; out = b(tril(true(size(b))));

9 years ago | 2

Answered
How can I solve this problem?
function [x,y,r] = InsideCircle (P1,P2) d = (P1-P2)/2; r = min(abs(d)); x = P2(1)+d(1); y = P2(2)+...

9 years ago | 1

Answered
How to vectorize the loops
if |dv| -scalar: out = permute(sum(delta*exp(dv)),[2,3,1]); if |dv| - vector: out = permute(sum(... reshape...

9 years ago | 2

Answered
Error using exponents in a small mathematical equation
|exp^7| -> |exp(7)| and |ln(524*a)| -> |log(524*a)| A = (-3.5*a)^3 + exp(7)/log(524*a) + 206^1/3 ;

9 years ago | 2

| accepted

Answered
identify a matrix within a matrix
Bad variant A = [9 7 6 5 4;6 7 5 4 2;7 7 5 5 5;7 6 4 4 3] B = [7 7;7 0]; p = abs(filter2(B,A) - norm(B(:))^2) < e...

9 years ago | 3

| accepted

Answered
For loop trouble!
w = 100; gravity = 32.2*12; m = w/gravity; k = 326.32; K = [2 -1 0; -1 2 -1; 0 -1 1]; K = k*K; M = [1 0 0;...

9 years ago | 0

Answered
How I can eliminate days with incomplete hours?
[~,~,c] = unique(EXAMPLE(:,1:3),'rows'); t = nonzeros((1:max(c))'.*(accumarray(c,1) == 24)); out = EXAMPLE(ismember(c,t)...

9 years ago | 0

Answered
Comparing two cell arrays of different sizes
A = { '1GY' [4.26319] [ 32.737586] [ -97.055721388888884] [] '4KS' [4.26310] [ 32.73758...

9 years ago | 1

| accepted

Answered
How can I remove elements divisible by 3,4, and 5 in a vector?
x = (1:50)'; out = x(all(bsxfun(@rem,x,3:5),2));

9 years ago | 1

Answered
mean value with time blanks
Hi Thodoris! Let |data| - your data ( _a matrix with two columns: time(hours) & temperature_). dff = [0;diff(data(:,1))]; ...

9 years ago | 0

Answered
How to do loop in the Workspace?
C = cat(1,c1,c2,c3,c4); d = reshape(mean(C,2),size(c1,1),[]); or C = cat(1,c{:}); d = reshape(mean(C,2),size(c1...

9 years ago | 2

Answered
mean vaue every one minute
data = [12.3539 25.8 12.3537 24.9 12.3590 25.1 12.3624 25.3 12.3692 24.5 12.3726 26.2 12.3777 26.1 12.381...

9 years ago | 0

| accepted

Answered
Creating an Array with nested for loops.
A = 1:4; m = numel(A); [ii,jj] = ndgrid(1:2*m-1); out = A(max(abs(ii-m),abs(jj-m))+1); or m = numel(A); ...

9 years ago | 0

| accepted

Answered
Assign loop values into each rows
sp11 = conj(p1).*p1; sp33 = conj(p3).*p3; sp12 = conj(p1).*p2; sp34 = conj().*p4; H12 = sp11./sp12; H34 = sp33....

9 years ago | 0

Answered
How to vectorize(?) user defined function with vector inputs.
function [output_vec] = myfunc(v1, v2, a, b) output_vec = zeros(2,size(v1,2)); el2 = quantile(v2, b); el1...

9 years ago | 0

Answered
Creating a Cell Array from multiple excel sheets
out = cell(100,1); for jj = 1:100 out{jj} = xlsread('path_to_your_xls_file.xlsx',jj); end

9 years ago | 0

Answered
I have a vector like x=[2 3 1 5],how could I generate a vector like [1 2 1 2 3 1 1 2 3 4 5]?
x = x(:); ons = ones(sum(x),1); ii = cumsum(x)+1; ons(ii(1:end-1)) = ons(ii(1:end-1)) - x(1:end-1); out = cumsum(o...

9 years ago | 0

Answered
Generating a new matrix
A = rand(4) >= .5; Alpha = ~A * pi;

9 years ago | 2

| accepted

Answered
Clustering data from index
[a,~,c] = unique(ID); out = ID(any(ismember(ID,a(accumarray(c,1) > 1)),2),:);

9 years ago | 0

Load more