Answered
Is there a more efficient way of coding this exact solution without it taking 20min to solve?
You are spending a lot of time calling on ‘integral2’ repeatedly when that integral can easily be evaluated as a relatively simp...

9 years ago | 0

| accepted

Answered
Accuracy of integral function.
I see an error. The line f = @(x) (4*k/q)*( atan(tan(q*phi/4*k)*exp(-x/Lb))+ atan(tan(q*phi/4*k)*exp(-(d-x)/Lb))) shou...

9 years ago | 0

Answered
How can I find specific values inside of a matrix?
Use 'histc' or 'histcounts' functions.

9 years ago | 0

Answered
Retain IDs of rows kept by the Unique function
[U,m] = unique(A(:,1:2),’rows’); B = [U,m]; I'm not sure which you want to keep, the indices of the "kept" rows or tho...

9 years ago | 1

| accepted

Answered
Can someone explain why atan (and atand) return inconsistent results for 0 - j compared to just -j? (see code and output below)
The inconsistency is caused by the sign which is assigned to the real parts of z and z1. In the case of z, the real part is a p...

9 years ago | 1

| accepted

Answered
How to graph irrational functions
I think what you are trying to do is this (it’s just a guess.) s = linspace(-3,2); k = -1./(s+3); plot(s,k) Note: ...

9 years ago | 0

Answered
How to solve linear simultaneous equations using determinants?
Use Cramer's rule.

9 years ago | 0

Answered
In row mean of consecutive columns up to end
A = rand(1,100); M = mean(reshape(A,5,[]),1);

9 years ago | 1

Answered
How to add NaN columns in a vector?
Let X be your row vector. p = cumsum([1,1+floor(abs(diff(X))/0.0002)]); T = NaN(1,p(end)); T(p) = X; X = T; ...

9 years ago | 1

Answered
Computing an Expectation in Matlab
The code x = 0:16; E = sum(x.*binopdf(x,18,.96)); should give you the answer.

9 years ago | 0

Answered
Can I manually set my least square line to begin from the origin?
Let your data be two vectors X and Y of the same size. Then the least square straight line running through the origin would be ...

9 years ago | 0

| accepted

Answered
Plotting complex numbers in z plane
For the magnitude and phase of a complex number use matlab functions ‘abs’ and ‘angle’. (The angle will be in radians from -pi ...

9 years ago | 1

Answered
Solving a summation for unknown limits of integration
There will be infinitely many levels r that make your inequality true. I believe you really want to find the first such level. ...

9 years ago | 0

Answered
Rearranging elements in a 2D array
RandomArray=sort(RandomArrayI:)); If the original sizes are desired, add this: RandomArray = reshape(RandomArray,20,5)...

9 years ago | 0

| accepted

Answered
how to plot a method in matlab
year = 365; y=ones(year,1); for i=2:year y(i) = y(i-1)*((year-i+1)/year); end

9 years ago | 0

Answered
Three input statements in 'and function'
It would either be: a(~(CLO<1&ACT>=1&ACT<5)) = -4; or if you were determined to use the ‘not’ and ‘and’ forms, a(no...

9 years ago | 0

Answered
How to iteratively multiply a vector by a matrix iteratively
The the product p_t0*P produces a five-element vector so you should write: ...... p = zeros(tf,5); % <-- for more effi...

9 years ago | 1

| accepted

Answered
qickyly change 3D matrix to 2D matrix
You could accomplish that with: a = reshape(permute(A,[3,1,2]),size(A,3),[]); [Note: You really haven’t specified how th...

9 years ago | 0

| accepted

Answered
I am trying to create a random 10x10 matrix that each row is equal to a certain value, what would be the best way of carrying this out?
As Walter has stated, you can use the routine I contributed to the File exchange called “randfixedsum” for each of your ten rows...

9 years ago | 0

Answered
How to find matrix dimensions while using * operator ?
Your error lies in the expression 20*log10(f).^40*log10(f+0.4) Here you are using matrix multiplication on two thousand-...

9 years ago | 0

Answered
how to plot a quadrangle
If the four (x,y) points are vectors P1, P2, P3, and P4, plot([P1(1),P2(1),P3(1),P4(1),P1(1)],[P1(2),P2(2),P3(2),P4(2),P1(2...

9 years ago | 0

| accepted

Answered
How to rotate rows of a matrix?
I think a for-loop is your best bet: for k = 1:size(A,1) f = find(A(k,:)==1,1); A(k,:) = circshift(A(k,:),1-f); ...

9 years ago | 1

| accepted

Answered
Find the sum of the first n
Or how about this one-liner: H = det(diag(2:n)+ones(n-1))/factorial(n); inspire by http://oeis.org/A000254.

9 years ago | 0

Answered
While loop not stopping
In addition to KSSV’s correction, there is another fundamental difficulty with your procedure. In effect you are attempting to ...

9 years ago | 0

Answered
The angle and distance between the two vectors.
You have a known vector u = [a,b] and an unknown vector v = [c,d]. The distance as you have defined it is a known r = sqr...

9 years ago | 0

| accepted

Answered
How can I fix the error "Index exceeds matrix dimension
The reason for the error message is undoubtedly the fact that d has only 26 elements, not one hundred, so d(1:100) is invalid. ...

9 years ago | 0

Answered
why matlab not calculating all values in loop?
In the line “for s=numel(power_consumption)” you should have written: for s=1:numel(power_consumption)

9 years ago | 0

| accepted

Answered
I have a discete probability distribution (histogram) and want to invoke rand to produce n random samples that follow the distribution specified by the histogram -how?
p = sum(bsxfun(@le,[0,0.1,0.6,0.7],rand(n,1)),2); (Note: Since this is a probability distribution, you cannot always expect...

9 years ago | 0

Answered
How to write a matlab-function which counts the n! with help of a vector?
function f = nfac(n) f = []; h = 1; for k = 1:n h = h*k; f = [f,h]; end return

9 years ago | 1

| accepted

Load more