질문


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년 초과 전 | 답변 수: 3 | 3

3

답변

답변 있음
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년 초과 전 | 0

| 수락됨

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

8년 초과 전 | 0

| 수락됨

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 1

| 수락됨

답변 있음
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년 초과 전 | 0

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

8년 초과 전 | 0

| 수락됨

답변 있음
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년 초과 전 | 0

| 수락됨

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

8년 초과 전 | 2

| 수락됨

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 1

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 1

답변 있음
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년 초과 전 | 1

| 수락됨

답변 있음
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년 초과 전 | 1

| 수락됨

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 0

답변 있음
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년 초과 전 | 2

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

8년 초과 전 | 1

| 수락됨

답변 있음
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년 초과 전 | 1

답변 있음
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년 초과 전 | 0

| 수락됨

답변 있음
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년 초과 전 | 1

답변 있음
Remove specific entry in a cell array
animals(ismember(animals,'dog')) = [];

8년 초과 전 | 7

| 수락됨

답변 있음
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년 초과 전 | 0

| 수락됨

답변 있음
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년 초과 전 | 1

| 수락됨

답변 있음
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년 초과 전 | 1

더 보기