Answered
find corresponding elements in a vector
A general approach: If the number of elements is n for both U and V, you can easily construct an n-by-n logical matrix, L, in...

8 years ago | 0

| accepted

Answered
Solving matrix with some known column values
By your assumption, for any i for which x(i) is already known, the corresponding coefficient A(i,i) will be unknown, while all A...

8 years ago | 1

| accepted

Answered
Find intersection point of two lines when I have their coordinates ?
The result of the three steps I mentioned would be: xy = [x1*y2-x2*y1,x3*y4-x4*y3]/[y2-y1,y4-y3;-(x2-x1),-(x4-x3)]; I do...

8 years ago | 5

| accepted

Answered
How can I calculate the angle between two surfaces?
The command [Nx,Ny,Nz] = surfnorm(Z) will return surface normals to surface Z. See: https://www.mathworks.com/help...

8 years ago | 0

| accepted

Answered
A substitute for this 'for' loop
It is important for efficiency’s sake that you initially allocate a sufficient amount of space for the w1 array before entering ...

8 years ago | 1

| accepted

Answered
How to find the points furthest from a linear regression line?
If by “furthest” you mean furthest in a direction orthogonal, (rather than vertical,) to your regression line, then do the follo...

8 years ago | 1

Answered
Matrix calculation without a For loop
Given the assumption that A is 1 by N, do this: C = A(:)*A; D = bsxfun(@plus,A(:),A)./C;

8 years ago | 0

| accepted

Answered
Pythagorean triples up to Z without loops
Instead of ‘meshgrid’ I would suggest using ‘ndgrid’: [a,b,c] = ndgrid(1:Z); A = [a(:),b(:),c(:)]; t = A(:,1).^2+A...

8 years ago | 0

| accepted

Answered
how to plot Zakharov function? Can anyone help me pls
[X1,X2] = meshgrid(linspace(-10,10,81)); T = .5*1*X1+.5*2*X2; Z = X1.^2+X2.^2+T.^2+T.^4; surf(X1,X2,Z)

8 years ago | 0

Answered
I am trying to find the number of nonzero elements I have in a matrix without using the nnz function.
If M is your matrix do this: s = sum(M(:)~=0);

8 years ago | 1

| accepted

Answered
How to fix this error 'Error using xor Matrix dimensions must agree'?
Your a1 and a3 arrays would have different numbers of columns unless the ‘c’ value is exactly half of size(BW,2), so an ‘xor’ op...

8 years ago | 1

Answered
how to group data points in matrix
Assuming all numbers in X lie between 0 and 40, and that X is a column vector as indicated in your description, then do: co...

8 years ago | 0

| accepted

Answered
Nonlinear Tangent (trigonemetric) equation
You are not using 'fzero' correctly. It cannot use a function handle that produces a vector as yours does - in addition to a ch...

9 years ago | 0

Answered
How can I access the previous index of a vector?
You don’t appear to use ‘Xint’ for any other purpose than deciding whether to use integers or reals. Therefore I suggest you ch...

9 years ago | 1

Answered
how to find the end of major and minor axis of an ellipsoid
I will make some assumptions about the ellipse you describe: # The ‘a’ and ‘b’ values are the lengths of the ellipse’s semi-m...

9 years ago | 0

Answered
Build my own AND function
Your code doesn't achieve the 'and' function. In the case when both a and b are false, the valid 'and' result should be false, ...

9 years ago | 1

Answered
Im not sure how to tackle this error message, can anyone help?
The trouble is just as the error message states. On the left side of x(i+1) = ((33.5*x.^0.48)-4.768)/53.246; you are t...

9 years ago | 0

Answered
cube root of negative numbers gets complex numbers? Is it a bug?
It's not a bug. That complex value is one of the three valid cube roots of -8. If you want to get the real -2 value, use the '...

9 years ago | 3

Answered
generate y(n)=y(n-1)+x(n)
That is precisely what the matlab ‘cumsum’ function does: y = cumsum(x);

9 years ago | 0

Answered
To make vector compatible to matrix.
If Data.y is a vector, to make the matrix multiplication H'*Data.y valid, it must be a column vector with the same number of ele...

9 years ago | 0

| accepted

Answered
How can i position the minimum value in the first cell for each column, without changing the sequence?
[~,I] = min(A,[],1); for k = 1:size(A,2); A(:,k) = circshift(A(:,k),1-I(k),1); end

9 years ago | 0

Answered
Is that possible to take numerical integration over a semi-definite integral?
If a symbolic solution cannot be found for the inner integral, you can use the matlab function ‘integral2’ for your task. If yo...

9 years ago | 0

| accepted

Answered
How to replace the diagonal elements of a matrix with 0 fro avoiding self loops?
If your matrix M is not square and if you only want those diagonal elements changed to zero “if it is 1”, then you can do the fo...

9 years ago | 2

Answered
How do you add specific elements contained within a matrix to produce a new vector?
That's known as convolution, and you can use matlab's 'conv' function to do the required computation. w = conv(x,h); w =...

9 years ago | 0

| accepted

Answered
roots of septic polynomial
Use 'roots' function.

9 years ago | 1

Answered
How can I calculate all of the possible combinations of two 1x6 vectors?
V = [V1;V2]; n = size(V,2); p = dec2bin(0:2^n-1,n)-‘0’+1; M = zeros(size(p)); for k = 1:size(p,1); for m = 1:...

9 years ago | 0

| accepted

Answered
using finite differences to estimate the second derivative of cosh(2x)
I see some things that are haywire. 1. You haven’t defined x in time for use with ‘f’ - it is only defined inside the for-l...

9 years ago | 0

Answered
How can I create a loop that iterates thru +/- values of an array to find a solution?
If ‘data’ is a row vector and ‘summ’ is the desired sum, do this: n = length(data); d = dec2bin(0:2^n-1,n)-‘0’; d = r...

9 years ago | 1

| accepted

Answered
How to find the centroids and the angle between each of them?
Once you know the centroids as x-y coordinates, it is easy to find their distances and angles. Suppose A = [x1,y1], B = [x2,y2]...

9 years ago | 1

| accepted

Answered
How to draw random number from a Cauchy Distribution
To generate N random values of x with a Cauchy distribution where b is the half width at the half maximum density level and m is...

9 years ago | 1

| accepted

Load more