Answered
How do I code this in a more efficient way?
[m,n] = size(M); M = [zeros(1,n+2);zeros(m,1),M,zeros(m,1);zeros(1,n+2)]; out = 1/2*(M(x+1,y+1)+sum(sum(M(x:x+2,y:y+2...

10 years ago | 3

| accepted

Answered
Why is this function not recognizing the correct number of rows?
Change the line [R,~]=size(m); to R = 2; You want to do your maximizing along the second dimension, not the fo...

10 years ago | 0

| accepted

Answered
Finding the max indeces of a 3d matrix and setting all non max indeces to 0
Let M be your 3D array. [n1,n2,n3] = size(M); M = reshape(M,n1*n2,n3); z = zeros(n1*n2,1); I = zeros(n3,1); ...

10 years ago | 0

Answered
How do you write a MATLAB code that returns the indices of the elements that will sum to exactly half of the sum of all elements?
Here's a brute force method: n = length(a); s = sum(a)/2; ai = []; for k = 0:2^n-1 t = dec2bin(k,n)-'0';...

10 years ago | 0

Answered
I need to create all a list of all possible states
A = zeros(2^N,N); for k = 0:2^N-1 A(k+1,:) = 2*(dec2bin(k,N)-'0')-1; end

10 years ago | 0

Answered
how to find irreducible factors of a polynomial
What ring or field can the coefficients of your reduced polynomials belong to? It makes a difference as to their classification ...

10 years ago | 0

Answered
Finding sequences of consecutive 1s
Assume 'n' is a row vector. f = find(diff([false,n==1,false])~=0); [m,ix] = max(f(2:2:end)-f(1:2:end-1)); The value...

10 years ago | 2

Answered
How to remove rows having repeating elements from a matrix?
t = false(1,size(A,1)); for k = 1:size(A,1) u = unique(A(k,:)); t(k) = size(u,2)==size(A,2); end B = ...

10 years ago | 0

| accepted

Answered
Permutation without using perms, randperm, randsample
The logic in your 'if' part is faulty. When you do the test "find(newArray(i))==d", you are doing a test on a single-element ve...

10 years ago | 0

| accepted

Answered
using a double or triple for loop?
Jgg is correct that you wouldn't need matlab to do this problem, but if you generalize to have N number of dollars initially ins...

10 years ago | 0

Answered
how can i solve this ?
You could use matlab's 'ldivide' (back-slash) operator. (I assume the first equation was meant to be "-3x1-6x2+2x3=-61.5" with ...

10 years ago | 0

Answered
If the result of subtraction of two values in a image matrix is negative, the value is set to zero.
Very likely your image values are in 'uint8' format, and this is how matlab does its subtraction in that format. To do otherwis...

10 years ago | 0

| accepted

Answered
Passing through each element in a matrix just once and randomly
B = A(randperm(prod(size(A)))); The vector B will have each value of A once and only once in random order.

10 years ago | 2

| accepted

Answered
Largest three digit number in Matlab?
Following Walter's idea, if the number must be exactly representable I propose: 8^(2^8) If it doesn't have to be exact,...

10 years ago | 1

Answered
if i have tow matrix how to crossover of them ?
R = repmat(randi([0,1],4,1),1,4); C1 = A.*R+B.*(1-R); C2 = A.*(1-R)+B.*R;

10 years ago | 0

| accepted

Answered
I need Random many numbers
If you mean random integers, R = randi([0,255],65000,1); If you mean random real numbers, R = 255*rand(65000,1); ...

10 years ago | 0

| accepted

Answered
Why does MATLAB returns a different value when we use a function?
As you may be aware, in neither double precision nor single precision floating point format numbers such as you are using here, ...

10 years ago | 0

Answered
how to add column of a matrix
b = zeros(4,16); for k = 0:15 t = double(dec2bin(k,4)-'0'); b(:,k+1) = sum(bsxfun(@times,a,t),2); end ...

10 years ago | 0

Answered
Simpson's Rule
I think you made an error on the line for j = 1:n-1 It should be for j = 1:k-1 where k = n/2. As it stands n...

10 years ago | 0

| accepted

Answered
computing the infinite sum
It is my opinion that this problem would require something other than adding the given terms out sufficiently far for 14-digit a...

10 years ago | 0

Answered
How do I do greater than and less than in the same command then find the size?
This is very elementary matlab. Assuming 'mag' is a vector, do this: count = sum((7<=mag)&(mag<=8));

10 years ago | 1

Answered
Creating specific matrix from other matrix?
x2 = find(x~=0);

10 years ago | 0

| accepted

Answered
How can I separate these graphs?
You have given 'plot' a 201 x 5 matrix, F1, to be plotted against a 201 x 1 column vector, x'. Under those circumstances 'plot'...

10 years ago | 0

Answered
How to find standard deviation based on the mean and a point on the line?
If you mean that you have a single point on some valid Gaussian density distribution curve (and not just a sample) then two poss...

10 years ago | 0

Answered
Simultaneously fitting three equations to get model parameters?
You apparently have just one equation, namely "Ratio1+Ratio2+Ratio3=3", and two unknowns, A and B. In general such a situation ...

10 years ago | 0

Answered
Compute the acuarcy or error of the output?
Ymodel = 1*(Y>.5) + 0*(Y<=.5); % The model from the predictions (right half unnecessary) p = sum(abs(Y-Ymodel))/size(Y,2...

10 years ago | 0

| accepted

Answered
Normalizing columns of a matrix
Assume by "norm" you mean the usual 2-norm, and that your 10000 x 10000 matrix is named 'M'. n = sqrt(sum(M.^2,1)); % Comp...

10 years ago | 0

| accepted

Answered
Help ! two nonlinear equations
This doesn't solve your equations, but you can gain a better insight into their nature by expanding the cosine expressions in te...

10 years ago | 1

Answered
Random numbers from complex PDF
The probability of lying inside a circle about the center with radius R in the X-Y plane is P = 1-exp(-R^2/(G-1)) Theref...

10 years ago | 1

| accepted

Load more