Answered
May I ask how to choose random prime number in fix interval?
a = 2; b = 30; p = primes(b); p = p(p >= a); out = p(randperm(numel(p),1));

10 years ago | 0

| accepted

Answered
Finding the max indeces of a 3d matrix and setting all non max indeces to 0
variant [m,n,k] = size(A); % A - your 3d array a1 = reshape(A,[],k); z = max(a1); lgc = reshape(bsxfun(@eq,a1,z),...

10 years ago | 0

Answered
how to make the vectors length in the cell array equal
example: Let |A| - your cell array A = arrayfun(@(x)randi(45,randi([3 8]),1),1:10,'un',0); n = cellfun(@numel,A);...

10 years ago | 0

| accepted

Answered
making map in matlab
use <http://se.mathworks.com/help/matlab/ref/scatteredinterpolant-class.html |scatteredInterpolant|>: Let |X| - your data - a...

10 years ago | 0

Answered
How to get the length of the text elements in character array
f = fopen('20160427.txt'); c = textscan(f,'%s','delimiter','\n'); fclose(f); out = cellfun(@(x)x(1:end-10),c{:},'un...

10 years ago | 0

| accepted

Answered
Find function - index by rows?
Example: A = rand(15) > .4; % your array [i0,j0] = find(A); c = num2cell(sortrows([i0,j0],1),1); [i_out,j_out]...

10 years ago | 0

Answered
Select a block of data from a matrix
[m,n] = size(im_gray); [x,y] = size(block1);% block1 - array with size [20 x 20] b = reshape(permute(reshape(im_gray,x,m...

10 years ago | 0

Answered
3D matrix multiplications
C = bsxfun(@times,A,reshape(B,1,1,[]));

10 years ago | 0

Answered
Decompose and invert a cell array
A = {[1 3 4 5 7] [5 6 7 8] [8 9 5]}; m=cellfun(@numel,A); B = cellfun(@(x)[x,nan(1,max(m)-numel(x))],A,'un',0)...

10 years ago | 0

| accepted

Answered
how to count the number of zeros between 2 one's
num = [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0] measurements = regionprops(logical(~num), 'Area') m = [measurement...

10 years ago | 0

| accepted

Answered
How do I reshape a raw data matrix?
f = fopen('20160421.txt'); c = textscan(f,'%s %f %f'); fclose(f); [c0,~,c1] = unique(c{1}); out = [{nan},num2c...

10 years ago | 1

Answered
merging two cell type matrix
merged_matrix = bsxfun(@strcmp,finish_id,points_id')... - bsxfun(@strcmp,start_id,points_id'); ADD...

10 years ago | 1

| accepted

Answered
How to swapping values in matrix row ?
a=[1 6 6 8 9 5 7 2]; a(2,:) = fliplr(a(2,:));

10 years ago | 0

| accepted

Answered
Double sum of a series
function out = conv2_without_conv2(xinp,yinp) sx = size(xinp); sy = size(yinp); x = xinp(end:-1:1,end:-1:...

10 years ago | 0

| accepted

Answered
Slow Find Loop no vectorisation
Please try it: co = (1:2^16)'; [l0,i0] = ismember(image1(:),co); s = size(image1); [ii jj k] = ndgrid(1:s(1),1...

10 years ago | 0

| accepted

Answered
Evaluation of Integral at every value
example: pnot = -.5; a = 2; b = 4; f = @(s,a,b,pnot)a*s^2 + b*s + pnot; out = arrayfun(@(y)integral(@(x)f(x,a,b...

10 years ago | 0

Answered
How do I plot one row of a matrix for multiple matrix of same size?
s = randi(200, 14, 121, 39); % your array z = num2cell(permute(s,[3,2,1]),[1 2]); for jj = 1:numel(z) figure...

10 years ago | 0

Answered
Compute average in different columns of cell arrays without considering 0 values
z = cat(3,C{:}); x = squeeze(z(:,2,:)); out = (sum(x)./sum(x~=0))';

10 years ago | 2

| accepted

Answered
I want to generate a data structure array from data but I got an error.
q = {9.2214e-001 9.9978e-001 1.9119e-001 1.6482e-002 3.3307e+000 2.4170e-003 2.0419e+002 2.2406e+002 1.2648e+0...

10 years ago | 0

Answered
How do I create a array from two arrays with one of them being the decimals?
res = ar1 + ar2.*10.^-(floor(log10(ar2))+1);

10 years ago | 1

| accepted

Answered
find max of every 4 rows in a matrix and save in separate array
data = xlsread('sample_data.xlsx',1); [~,~,c] = unique(data(:,3)); idx = accumarray(c,(1:size(data,1))',[], @(x) x(...

10 years ago | 1

| accepted

Answered
average of range of values in a matrix
Hi friends! In four rows A = [1234 785 11 5678 457 11 9101 390 11 2467 381 16...

10 years ago | 0

Answered
I want to add some elements of a vector depending on the elements of other vector
t=[726835; 726835; 726835; 726836; 726836; 726837; 726837; 726837; 726837]; x=[1.80232785962791e-07;4.24203429768918e-07;2....

10 years ago | 0

Answered
how to fix this code ???
function [M_row , M_column] = mainfun(M) M_row = onestep(M.',1)'; M_column = onestep(M,2); function out = onestep...

10 years ago | 0

Answered
copy row or column with condition?
[m,n]=size(A); S = randi([0 1],[m,n]); t = bsxfun(@or,sum(A,2) > n/2,sum(A,1) > m/2); S(t) = A(t);

10 years ago | 0

Answered
Create n matrix from one matrix according to elements of a column?
[~,~,c] = unique(A(:,end)); M = accumarray(c,(1:size(A,1))',[],@(x){A(x,:)});

10 years ago | 1

| accepted

Answered
Sorting a matrix from smallest to biggest left to right
M = [4,7;5,8;6,9] out = reshape(M,size(M,2),[])';

10 years ago | 1

Answered
remove rows by pick the min value in another column
x=[55,-45,9.8 60,-40,11.2 60,-45,12.6 55,-40,14 55,-45,15.4 60,-45,16.8 60,-40,18.2 60,-45,19.6 ...

10 years ago | 0

| accepted

Answered
Repeating blocks of N rows M times
A = reshape(1:18,3.,[])'; N=2; M=2; [~,n] = size(A); A2 = reshape(kron(reshape(A',n*N,[]),ones(1,M)),n,[])...

10 years ago | 2

| accepted

Answered
How to remove duplicates from a matrix without using unique?
A = [1,2,3;1,3,3;4,2,1]; [a,ii] = sort(A); a([false(1,size(a,2));diff(a)==0]) = nan; [~,i1] = sort(ii); out = ...

10 years ago | 0

Load more