Answered
Using binornd function - problem with draw variability
By writing “binornd(1,p)” you are restricting yourself to the values 0 and 1 with probabilities 1-p and p. To get a larger rang...

10 years ago | 0

Answered
How does randperm with 2 arguments work internally?
[~,p] = sort(rand(n,1)); p = p(1:k); where p contains k unique values chosen from 1:n. Of course Mathworks may well u...

10 years ago | 0

Answered
Help please - How to extract row and column from matrix from certain value
[row,col] = find(M==1048); where M is your matrix.

10 years ago | 0

Answered
Add a number of zeros to matrix row depending on its content.
V = zeros(max(A),1); V(A) = 1; B = diag(V);

10 years ago | 0

Answered
how to write a function for the inbuilt function perms without using perms nor any built-in MATLAB permutation functions; nor any built-in string manipulation functions in the solution?
This is pretty clearly homework, so I doubt if anyone is going to state anything other than a hint. My own hint would be to wri...

10 years ago | 0

Answered
Approximation of a differential system in a specific point
This requires the use of one of Matlab’s ode functions such as ode45. See http://www.mathworks.com/help/matlab/ref/ode45....

10 years ago | 0

| accepted

Answered
Why isn't my integration using Trapezoidal Rule working?
The problem lies in the line x = pi/4:2:pi/3; It has only one point and 'trapz' is not happy with that. Try something ...

10 years ago | 1

| accepted

Answered
I'm trying to write a function that calculates the max min and mean based on how many output arguments are used to call the function and I'm not sure why this doesn't work
Your function doesn't yield its results. You need this: function [x,y,z] = calcvals(varargin) or something equivalent ...

10 years ago | 0

Answered
Matlab code for computing curvature equation
Your formula for curvature is that of a curve defined in terms of a parameter t in which x’, y’, x”, and y” all refer to derivat...

10 years ago | 1

| accepted

Answered
How to set a condition for sequential number of non NaN values in a vector?
Let M be your matrix. [m,n] = size(M); T = diff([true(1,n);isnan(M);true(1,n)],1,1); T2 = false(1,n); for k = ...

10 years ago | 1

| accepted

Answered
Generate new matrix from old matrix with specific conditions
[m,n] = size(R); f = 20; % <-- Check that f is a divisor of m A = reshape(cumsum(reshape(R,f,m/f,n),2),m,n);

10 years ago | 0

| accepted

Answered
Problem with equating for loop index to a variable.
You should read Cleve Moler's document on the subject at http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall9...

10 years ago | 1

| accepted

Answered
Convergence program stuck at a point.
I think you are confusing things with your names of ‘old’ and ‘older’. What you need are the concepts of “too high” and “too lo...

10 years ago | 0

| accepted

Answered
how to find all possible paths in MxM matrix
@Mohammad: Here is code that does not require any rejections - every row of matrix A represents a valid “path”. It differs from...

10 years ago | 0

Answered
Create an array based on another array's input
Use the ‘histc’ function, [~,ix] = histc(x,grade_ranges), then use ix to index into a vector [‘A’,’B’,’C’,’D’.’F’].

10 years ago | 0

Answered
how to find visual angle
The true angle between ba and bc would be: ang = atan2( abs((xa-xb)*(yc-yb)-(ya-yb)*(xc-xb)) , ... (xa...

10 years ago | 0

Answered
Fixed Point Iteration - initial guesses
I think what you need, instead of the simple for-loop you have described which just executes a fixed number of times, is a while...

10 years ago | 0

Answered
How can i know through MATLAB tool that given function is convex or not?
If your function has a second derivative, it is convex if and only if that second derivative is always non-negative. If the sec...

10 years ago | 0

Answered
How do I test if a matrix is unitary?
Again, e^(i*H) is not the same as exp(i*H). Check matlab's "mpower" operator.

10 years ago | 1

| accepted

Answered
How do I show that my matrix is unitary?
The problem lies in your interpretation of the expression e^(i*H). It is NOT the same as exp(i*H). What is called for here is ...

10 years ago | 1

Answered
find nearest value on matrix
result = min(b(b>=1250)); For this to work, there has to be at least one element of b that is greater than or equal to 125...

10 years ago | 1

Answered
Can finite difference method can be expressed with diff function?
Assuming A is n x n, B = diff(A,2,1)+diff(A,2,2); The array B would be of n-2 x n-2 size. The second argument of 2 in e...

10 years ago | 0

Answered
Error in writing an equation (sin function)
The line Z=sin(X)*sin(Y)/(X*Y).; is the trouble. You need dots there: Z=sin(X).*sin(Y)./(X.*Y); so as to prod...

10 years ago | 0

| accepted

Answered
how to get 1 to 500 odd numbers sum in matlab?
sum is (1+499)*250/2 Note: Legend has it that ten-year-old Carl Friedrich Gauss was given a similar problem by his instruc...

10 years ago | 2

Answered
Create a new matrix with 0,-1 and 1 if and where in another matrix appears a max value
B = bsxfun(@eq,A,max(A,[],2))-bsxfun(@eq,A,min(A,[],2)); Note: I am taking you literally in regard to the equalities you r...

10 years ago | 0

Answered
Creating a plane normal to an ellipsoid
Matlab’s ‘ellipsoid’ function, [x,y,z] = ellipsoid(xc,yc,zc,xr,yr,zr) creates an ellipsoid whose equation is: f(x...

10 years ago | 1

| accepted

Answered
How to compute Permutation without repetition?
If a, b, c, etc. are different numbers, do this: v = [a,b,c,d,e,f]; P = perms(v); P = P(:,1:5); The matrix P wi...

10 years ago | 1

| accepted

Answered
Removing duplicate rows (not "unique")
Let A be your matrix. [B,ix] = sortrows(A); f = find(diff([false;all(diff(B,1,1)==0,2);false])~=0); s = ones(lengt...

10 years ago | 1

| accepted

Answered
Permutations of string without repetitions
As Stephen has warned you, twenty-five characters is a dangerous number to apply this problem to. Let’s talk about some more se...

10 years ago | 4

Load more