Answered
How to multiply each element with next one in the same row, then sum the product
A = [-1 -1; -1 1; 1 -1; 1 1]; nA = size(A, 2); B = [sum(A, 2), sum(A(:, 1:nA-1) .* A(:, 2:nA), 2)] The 2nd column of B is t...

4 years ago | 0

Answered
Problem in using mxSetPr with USHORT
Either use memcpy instead of copying the data in a loop. Or use mxSetData instead of mxSetPr, if you are really sure, that the ...

4 years ago | 0

| accepted

Answered
Matlab doesn't show imaginary part of complex numbers for me!
Do you see the 2 trailing zeros? This looks like the "bank" format: format long g pi + 2i format bank pi + 2i Solution: Do ...

4 years ago | 0

Answered
Runge-kutta results do not align with ODE45 solver, what am I doing wrong?
You are using wrong initial values in the Runge Kutta method: % X(:, 1) = RHS(0, V0); Nope! X(:, 1) = V0; The inital values ...

4 years ago | 0

| accepted

Answered
Error when attempting to activate license - Host ID is not valid
Spaces? Is the 2nd character an uppercase o? Type it again: 20BE526B . I have troubles opening the page with my license current...

4 years ago | 0

Answered
How to extract random subset of images from a cell array?
Of course randperm works with cell arrays: random_subset = im_(randperm(numel(im_), 100)); This selects 100 elements in random...

4 years ago | 0

| accepted

Answered
getappdata / setappdata does not work for me?
After the line figImage = figure; the variable figImage contains the handle of the figure. If you want to use this handle in a...

4 years ago | 0

| accepted

Answered
What is the equivalence startup fcn in Guide?
I assume you mean the CreateFcn.

4 years ago | 0

| accepted

Answered
Undocumented startup option / Starting MATLAB GUI from Java
As far as I remember, starting Matlab with the Java VM was optional in Matlab 4 or 5. So you could enable the JVM manually. Ther...

4 years ago | 1

Answered
Determining smoothness of a trajectory
You have to start with a mathematical definition of what you call "smooth". Do you mean differentiable? This cannot work. There...

4 years ago | 0

Answered
Check the flipped of 3D Array matrix
Do you mean: isequal(A, flip(A, 2)) If A is huge (e.g. 1 GB), this operation is not efficient, because it duplicates the Array...

4 years ago | 0

| accepted

Answered
matlab structure to csv file
% [EDITED] Adjusted for comma separators: coef.header = {'mexico', 'france', 'berlin', 'italy', 'china', 'srilanka'}; coef.da...

4 years ago | 1

| accepted

Answered
How to fprintf a transposed matrix?
fprintf takes the argument elementwise as they are store in the memory. So: A = [7 11; 15 23; 9 7]; fprintf(' %d \t %d \t %d\n...

4 years ago | 0

Answered
problem in plot while loop
k0 = 2 * pi / 0.6328 * 1e6; t2 = 1.5e-6; n1 = 1.512; n2 = 1.521; n3 = 4.1-1i*0.211; n4 = 1; m = 0; x = 1.512; t3 = 1e-...

4 years ago | 0

| accepted

Answered
How to plot Multivariable ODE with conditions ?
You are asked to do this in Simulink, not in Matlab. In Matlab a numerical solution is a better idea than hoping, that there is...

4 years ago | 1

| accepted

Answered
Is there any way to code this on a different way?
No. This is the efficient solution already. To get the 100.th most frequent element, you have to determine the frequencies of al...

4 years ago | 0

| accepted

Answered
requirements to install Matlab, need compilers or tools
You can keep the old Matlab version. If you need a compiler depends on what you want to do with Matlab. For the Coder, compilin...

4 years ago | 0

Answered
how can I modify a triple "for" cycle to run faster?
Of course you have to pre-allocate. ntables = 50; nlines = 10000; ncolumns = 30; B = zeros(ntables, nlines, ncolumns); f...

4 years ago | 0

| accepted

Answered
How can I rearrange a vector?
Some bold guesses of what you want to achieve: aa = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9]; a = aa; a(a >= 5) = 0 a = a...

4 years ago | 0

| accepted

Answered
How do I avoid the error message "Index exceeds the number of array elements" in a for loop?
day(1):day(3) is the vector 1:13. Some other simplifications, which uses a counter to access the days: folder = 'C:\Users\Do...

4 years ago | 1

| accepted

Answered
How to vectorize the MATLAB code?
a = rand(1, 11); N = length(a); b = zeros(1,N - 1); for i = 1:N-1 b(i) = a(i) + a (i + 1); end % Vectorized 1: b2...

4 years ago | 2

| accepted

Answered
Variable "H" might be set by a nonscalar operator
If H is an array, what is the meaning of: if H < 0.5 ? The IF command requires a scalar condition. Therefore Matlab inserts an...

4 years ago | 0

Answered
Why has matlab become extremely inefficient with global variables?
You do not use global variables, but a script. Although you declare the varaibels as globals inside the script, there is no need...

4 years ago | 0

Answered
Rotating coordinate system inside loop
a=4; b=4; ab=a*b; Input=zeros(ab,2); for ii=1:a Input((ii-1)*a+1:ii*a,1)=(a-b:-2:-(a+b)+2)'+2*(ii-1); Input((ii-...

4 years ago | 0

| accepted

Answered
why am I getting "Array indices must be positive integers or logical values"
The variable Fs has the value 5. Then the expression: Fs(0:(L/2)) is treated as indices. 0 is not a valid index. In addition F...

4 years ago | 0

Answered
Subtraction is not working in while loop
If you do not change the value of the variable used in the condition of the while loop, this loop must run infinitly: x = rand;...

4 years ago | 0

Answered
Why do I receive an error with the save function?
save gets the name of the variable, nit the variable itself: save(matFile, 'mypadCBCTimage', '-append', '-nocompression'); % ...

4 years ago | 0

| accepted

Answered
Problem using if statements in for loop
Welcome to the world of numerical maths. See: FAQ: Why is 0.3-0.2-0.1 not equal to zero? The standard example is: any((0:0.1:1...

4 years ago | 0

Answered
Moving Average with timestep
A simple average over 2 elements (length of M can be even or odd): Len = numel(M); v = (M(1:2:Len - rem(Len, 2)) + M(2:2:Len...

4 years ago | 0

| accepted

Answered
Assign nearest maximum value.
Why 30 and not 20? Both have a distance of 5. A = [10,20,30,40]; S = 25; [~, index] = min(abs(A - S)); A(index)

4 years ago | 0

Load more