Answered
How C++ gets struct values from Matlab
For char array #include "mex.h" /* File test.c mex file demo access to a string of s.name * * >> mex test.c * >> s = str...

5 years ago | 0

Answered
How do I reference the element of a matrix in a loop?
k and l inside the for-loops are scalars, thus you can't take an indexing k(s) or l(s). Now what your code supposes to do and h...

5 years ago | 0

| accepted

Answered
Optimizing calculation in for loop for convolution
Use error function ERF x = -100:0.01:100; sigma = 5; tzero = 10; to = min(x)+3*sigma:0.01:max(x)-3*sigma; convfun = @(t) sq...

5 years ago | 0

| accepted

Answered
Create a matrix [3xm] with the elements of a matrix [3,n] in the order given by vector k[m]
plot3(... [FV2Unique(:,1),FV1Unique(k,1)]',... [FV2Unique(:,2),FV1Unique(k,2)]',... [FV2Unique(:,3),FV1Unique(k,3...

5 years ago | 0

| accepted

Answered
How to take an average of row elements in a two-column matrix when both elements do not contain a NaN, but use only the non-NaN value when there is a NaN?
>> A=[2 2; 4 NaN; 9 1] A = 2 2 4 NaN 9 1 >> mean(A,2,'omitnan') ans = 2 4 ...

5 years ago | 1

| accepted

Answered
Error compiling the codes with the mcc command
Maybe the oldbuilt mexfile is being used?

5 years ago | 0

Answered
Cell array summation when arrays are different sizes
I do just one, let you adapt to the second. cellname = {... [1 1 1; ... 2 2 2; ... 3 3 3], ... [1 1 1; ... 2 2 2; ... 3 3...

5 years ago | 1

Answered
How to measure the volume of a cone using surface area of triangles in matlab
Your post is not clear (see our comments). However I guess what you want is approximate the volume of the (cone) object from the...

5 years ago | 0

| accepted

Answered
How can I make this code run faster?
M = 1000; N = 500; P = 1000; sum_Load = rand(1,M); % For demonstration purposes Pseudo_Load_Factor = rand(N,P); ...

5 years ago | 1

| accepted

Answered
selection of 4 consecutive rows from a matrix randomly
Shorter code % Test data A = rand(2500,3); A(:,1) = 1:size(A,1) % <= put here the original row number for you to observe them...

5 years ago | 0

Answered
selection of 4 consecutive rows from a matrix randomly
Each page of B is a random 4 consecutive rows of A. All rows are shuffled. % Test data A = rand(2500,3); A(:,1) = 1:size(A,1)...

5 years ago | 0

Answered
Quasi-Newton method for optimization
Use FMINCON to minimize norm(r*x-R)^2 with constraints sum(x)=1 x>=0 r=[0.22 9.94 0.08; 0.16 0.95 0.08; ...

5 years ago | 1

| accepted

Answered
All the combinations of sums of rows of matrices
Code for arbitrary number of matrix A=[... 1 0 2 1 2 4 1 3 0 1 3 2]; B=[... 1 3 0 ...

5 years ago | 1

| accepted

Answered
Removing empty cells with non-zero dimensions
I like your for-loop; you might speed up a little bit for i=1:N Xi = X{i}; Xi(cellfun('isempty',Xi)) = {[]}; % switch...

5 years ago | 0

Answered
Histogram to a CDF/PDF
A=[a(1:135756).column1]; figure subplot(2,1,1); histogram(A,'Normalization','pdf'); ylabel('pdf'); subplot(2,1,2); histo...

5 years ago | 1

| accepted

Answered
Find corresponding values of discritized data after using splitapply
if x is extracted as the first column of your array A slice_x = splitapply(@(x) {x}, A, disc_x);

5 years ago | 0

| accepted

Answered
Calculation with elements in row before or after
>> a= [1 2 3 4 5; 6 7 8 9 0]; >> a a = 1 2 3 4 5 6 7 8 9 0 >> conv2(a,[1;1...

5 years ago | 0

| accepted

Answered
set of points form a polygon?
If your list of points are ordered of the boundary of the polygonal, you can detect if the list of points self intersect thus NO...

5 years ago | 1

| accepted

Answered
How do I remove columns or rows that are identical?
h = randi(2,2,20) % remove columns that are consecutively repeated lgt = diff(find([true, any(diff(h,1,2)~=0,1), true])); h...

5 years ago | 0

| accepted

Answered
How can I perform the following operation in matrix
If I understand correctly >> A=[2 3 4 5; 4 5 6 7; 3 4 5 6; 3 4 2 1] A = 2 3 4 5 4 5 6 ...

5 years ago | 0

| accepted

Answered
Find element wise minimum of 4 matrices, while remembering which matrix the minimum element came from
iwhich = 1 => A, 2 => B, 3 => C, 4 => D [minABCD,iwhich] = min(cat(3,A,B,C,D),[],3);

5 years ago | 0

Answered
Remove repeating variables and replacing them
x = x([true diff(x)~=0])

5 years ago | 1

| accepted

Answered
How can I get all the existing shortest paths between two single nodes for graph
Here is the code base on Bellman Ford algorithm which provides ALL shortest paths from a single node to ALL other nodes s = [1 ...

5 years ago | 3

Answered
least absolute deviation when we have data set
% Test data x = (1:10)'; y = 10 - 2*x + randn(10,1); y(10) = 0; order = 1; % polynomial order M = x(:).^(0:order); m = ...

5 years ago | 3

Answered
Sorting complex strings by a deliminator
One way c = {'c1-3' 247 247 247 97 0 0 'c1-4' 247 247 247 97 0 0 'c1-5' 247 247 247 97 0 0 'c1-1' 247 247 247 97 0 0 'c1-2'...

5 years ago | 0

Answered
Permutations of an array by fixing some element
array=[1 0 3 0 5 0] b = array~=0; A = zeros(factorial(sum(b)),length(array)); A(:,b) = perms(array(b))

5 years ago | 0

| accepted

Answered
Given a vector, I would like to sample without replacement elements from it repeatedly.
v = 'a':'z' % your vector n = 10; % number of "loop" s = 3; % number of drawing without replacement [~,ir] = maxk(rand(n,le...

5 years ago | 1

Answered
Someone please help me, I have probability mass function as follwing, How can generate 100 random values of j from this probability mass function?
alpha=0.01; lambda=0.99; f=@(j) ((1-alpha).^j-(-alpha).^j).*lambda.^j*exp(lambda*alpha)./(factorial(j)*(exp(lambda)-1)); p...

5 years ago | 1

Answered
How to find average of all dimentions of a matrix without including zerors
simply mean(nonzeros(a)) or mean(a(a~=0))

5 years ago | 1

| accepted

Answered
What frustrates you about MATLAB? #2
scatteredInterpolant miss a 2 C^2 of methods supported by griddata 'cublic' and especially 'v4'.

5 years ago | 0

Load more