Question


Mex inplace change problems R2015b and later
This post is to alert mex programmers of a change in R2015b and later that makes inplace changes more hazardous than they used t...

8 years ago | 3 answers | 3

3

answers

Answered
I have a matrix A (32000x2). I want to create a new matrix from matrix A, with only value 1 or 0 in coloumn 2 and delete other rows (which have decimal values).
A = your 32000x2 matrix A2 = A(:,2); % 2nd column of A result = A( A2==0 | A2==1, : ); % subset of A where 2nd column is 0 ...

8 years ago | 0

| accepted

Answered
How do i this in an efficient way?
C = sum(A(sub2ind(size(A),B(1:end-1),B(2:end))));

8 years ago | 0

| accepted

Answered
I am trying to run the following code-
dataset has only 8 columns, but you are trying to pick off columns 1:40 and 41, hence the error. You need to reexamine your code...

8 years ago | 0

Answered
Why does the first for loop stop at n=2999 instead of 3000 when t=0.6 and k=1/5000?
Floating point calculations are not always exact because MATLAB uses IEEE double precision for the calculations you are doing, a...

8 years ago | 1

| accepted

Answered
Do the inverse operation of this reshape?
Are you just trying to recover an original single line string? E.g., str = char(key+'0');

8 years ago | 0

Answered
How to take an average every four columns?
x = your 64x1844 matrix result = reshape(mean(reshape(x.',4,[])),size(x,2)/4,[]).';

8 years ago | 0

| accepted

Answered
How would find acceleration from two columns of data using this formulae? (I have velocity and time)
Hint: Given an Mx2 matrix called vt with first column velocity and second column time, look at using the diff( ) function on the...

8 years ago | 0

| accepted

Answered
how to sum multiple matrics inside a cell array?
result = sum([A{:}]);

8 years ago | 2

| accepted

Answered
Can someone explain to me why this sub-array behaves this way?
The (i,j)'th element of the result is made up of the (row_index(i),col_index(j)) element of the source. Since you have two row i...

8 years ago | 0

Answered
How can I call the first value from a for loop into a vector?
Remember the starting values prior to the loop. E.g., A = a; B = b; Then after the loop concatenate: vec = [A,B,...

8 years ago | 1

Answered
Elegantly refer to the second output from a function
Unless the function has an input argument syntax that specifies only returning B, you can't do this. You can throw away that A i...

8 years ago | 0

Answered
New to matlab and am getting index exceed matrix dimensions error
Did you mean that last p to be p2? E.g., should this S = sum(abs(y - p(1)*x.^2 - p(2)*x - p(3))); be this instead ...

8 years ago | 0

Answered
Apply function to all fields of a structure
What you have is likely the best way to do this. Since there will need to be a loop of some sort to do this anyway (even if it i...

8 years ago | 0

Answered
How does this code sum the first 100 even integers?
The code picks off the values of ctr that are even and adds them into the variable called sum (a lousy name for a variable btw b...

8 years ago | 1

Answered
Pick 5 Unique Random Numbers
A = your matrix n = number of elements of A to pick at a time (must be exactly divisible in numel(A)) x = reshape(randpe...

8 years ago | 1

| accepted

Answered
OR, Matrices and equality
The == and | operations you are doing are element-wise operations, so you get an element-wise result according to the precedence...

8 years ago | 1

| accepted

Answered
How do I use each value in a vector as its own variable to be tested in relation to another variable in its respective vector?
Use element-wise operators. E.g., x = a - b ./ c; % The ./ operator with the dot is element-wise division There also ele...

8 years ago | 0

Answered
Hello can someone show me a simple code to show the earths orbit around the sun using ordinary differential equations.
Your biggest problem is that you have a 4-element state vector defined with y0 (indicating only x-y plane motion), but your deri...

8 years ago | 0

Answered
Number of Elements Between 2 Elements in a matrix.
Assuming the matrix has exactly two nonzero entries: M = your matrix f = find(M'); % Transpose to get the row data into ...

8 years ago | 0

Answered
Maximum Recursion limit of 500 Reached Error.
You need to rewrite your logic so that your circle3 function has a way to return to the caller. As it is now, the only thing tha...

8 years ago | 2

Answered
Why is my plot not showing anything?
Use element-wise division: y = ((x+5).^2)./(4+3*x.^2);

8 years ago | 1

| accepted

Answered
How to add values from two different arrays into a matrix
On later versions of MATLAB: c = a + b; On earlier versions of MATLAB: c = bsxfun(@plus,a,b); In MATLAB, variabl...

8 years ago | 1

Answered
Matlab confusion of function and variable names after load
The load command 'poof'ed a variable into the function workspace after the parser had parsed the m-file and associated "alpha" w...

8 years ago | 0

| accepted

Answered
mex error. undefined reference
Unless all of the source C files are explicitly #include in your nlopt_optimize.c file, you must list them explicitly in the mex...

8 years ago | 1

Answered
Remove specific entry in a cell array
animals(ismember(animals,'dog')) = [];

8 years ago | 7

| accepted

Answered
5th Order Runge Kutta
E.g., 5th Order Runge-Kutta-Fehlberg coefficients can be found here: <https://en.wikipedia.org/wiki/Runge%25E2%2580%2593Kutta...

8 years ago | 0

| accepted

Answered
How to plot different parts of one vector with different colors?
Something like this if you go with the segmented approach: ix = { 1:523, 524:704, 704:numel(time1) }; colors = 'gyr'; ...

8 years ago | 1

| accepted

Answered
Coding Practice: When to use a structure rather than separate variables?
I prefer using a single double matrix to store the x-y-z data. E.g. storing each x-y-z triplet as a column, which makes it easie...

8 years ago | 1

Load more