Risposto
How do I fill a matrix of 1s and 0s with sequential numbers
nnza = nnz(A); nnzb = nnz(B); At = A'; Bt = B'; At(logical(At)) = 1:nnza; Bt(logical(Bt)) = (nnza+1):(nnza+nnzb); Aresult ...

circa 6 anni fa | 0

| accettato

Risposto
How to quickly find the column index of the last non-zero element in all rows in a sparse matrix?
You can use a mex routine for this and avoid all temporary data copies. E.g., a direct approach: /* File: find_last_nz.c *...

circa 6 anni fa | 3

Risposto
How can I find the difference between values in an array with an index spacing of 2?
Hint: Look at x(1:2:end) and x(2:2:end). If x has an even number of elements, you could reshape(x,2,[]) and then look at some ...

circa 6 anni fa | 0

Risposto
How can I print the result of a function using fprintf? (matrix and string!)
When comparing strings, it is not a good idea to use the == operator, which is an element-wise operator. Instead, use a string ...

circa 6 anni fa | 2

Risposto
Voltage of a capacitor as a function of time
Maybe the function you want is cumsum( ) instead of sum( )?

circa 6 anni fa | 0

| accettato

Risposto
Pythagorean Triples with Loops
E.g., an outline % (1) insert code here to ask for the largest value n for a=1:n for b=a:n for c=b:n ...

circa 6 anni fa | 0

Risposto
Describing the motion of a composite body using system of second order differential equations
In this line: xy(2)=x(2)*x(2)*tan(x(1))-xy(4)*4*sec(x(1)); you are using xy(4) before it is defined. That is, you have t'' d...

circa 6 anni fa | 0

| accettato

Risposto
Quaterion Creation In Simulink
See these posts for discussions of the MATLAB quaternion convention: https://www.mathworks.com/matlabcentral/answers/352465-wha...

circa 6 anni fa | 0

| accettato

Risposto
rotate acceleration vector using rotation matrix
You can use a loop, e.g. acc = your 940x3 matrix r = your 3x3x940 array result = zeros(size(acc)); for k=1:size(acc,1) ...

circa 6 anni fa | 0

| accettato

Risposto
C MEX file issue in for loop
These lines do not do what you think they do: double* data : ... data[j,i] ... From your code it is obvious that you thi...

circa 6 anni fa | 0

| accettato

Risposto
Why 0.35 divide 0.001 return double, and 0.34 divide 0.001 return int.
Welcome to the world of floating point arithmetic. In one case, the result is 340 exactly so it prints without any trailing 0's...

circa 6 anni fa | 3

Inviato


SHAREDCHILD creates a shared data copy of contiguous subset
SHAREDCHILD creates a shared data copy of a contiguous subsection of an existing variable

circa 6 anni fa | 2 download |

5.0 / 5

Risposto
Stop value in loop for repeating
Not sure if you need the numbers to be different or not. Either this: for k=i:length(myprime) or this for k=i+1:length(myprim...

circa 6 anni fa | 0

| accettato

Risposto
Simplifying complex multiplications by means of polar coordinates
It looks like your accumulation is trying to sum polar coordinates. You can't do that. I.e., if you have (r1,theta1) and (r2,t...

circa 6 anni fa | 0

Risposto
How to put a name on each double variable in a cell array"
You could have an associated cell array for the file names. E.g., fnames{i,j} = fn;

circa 6 anni fa | 0

| accettato

Risposto
2nd Order ODE
For a numerical solution, you could try this function: https://www.mathworks.com/help/matlab/ref/bvp4c.html

circa 6 anni fa | 1

Risposto
Converting Parameter from mxArray to a C-Style String
If it is a single quote ' ' char array, then just char *cp; cp = mxArrayToString(prhs[2]); If it is a double quote " " string...

circa 6 anni fa | 1

Risposto
HOW to create 4D array and 3D array
Fortran allows negative and 0 indexing, but MATLAB does not. There is no double class equivalent of this in MATLAB. You would ...

circa 6 anni fa | 0

Risposto
How to combine matrices
This sounds like a job for cell arrays. E.g., read here: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-va...

circa 6 anni fa | 1

Risposto
Adding a vector in a system of differential equations
One way is to create a function handle to pass in the extra parameters. E.g., function [output] = DiffEquations(time,init,iapp...

circa 6 anni fa | 0

Risposto
Index in position 1 is invalid. Array indices must be positive integers or logical values?
If you are trying to create an anonymous function, the syntax is: f = @(u,v) (sin((B*Lx)*u)/((B*Lx/2)*u))*(sin((B*Ly)*v)/((B*Ly...

circa 6 anni fa | 1

Risposto
Question about using randperm in a loop
If you want each number in the matrix to be unique, then don't call randperm( ) by row because that will not guarantee uniquenes...

circa 6 anni fa | 1

Risposto
Difficulties with interpreting and use of @ sign
You don't have to use all of the input arguments. The following is fine which ignores t: f = @(t,y)((y-1)*(y-2)); I.e., if y...

circa 6 anni fa | 2

Risposto
Speeding bitand / bitshift and type conversion
Try this: DataWord16 = typecast(DataWord1,'uint16'); % shared data copy for later versions of MATLAB Var1 = DataWord16(1:2:end...

circa 6 anni fa | 2

Risposto
Is there a fast way to get subsequences of a matrix with indices from a vector?
Unfortunately, you have the worst memory layout of your data for this. Each sub-matrix is scattered throughout memory so the ca...

circa 6 anni fa | 1

| accettato

Risposto
Given a matrix A^n. Comparing normal multiplication versus Diagonalization. I expect the former to be faster but its not in my case
Well, the timings didn't meet your expectations. Why would you expect A*A to be slower than doing a full eig calculation follow...

circa 6 anni fa | 0

Risposto
Taking 3-D matrices out of a 4-D matrix
What is wrong with accessing the 4D array using simple indexing? A(:,:,:,k) for k'th 3D array. You could also use cell arrays,...

circa 6 anni fa | 1

Risposto
loop through same equation
In your loop, y(i) and y(i-1) are scalar elements of y, not vectors. You need to use different syntax for the vectors. E.g., y...

circa 6 anni fa | 0

Risposto
Appending an asterisk to my output matrix if x > y
Add the ASCII codes for space and asterisk in the 4th column and print that column as a string. E.g., newMatrix(:,4) = ' '; ne...

circa 6 anni fa | 0

Risposto
Math function and plotting
You need to change that matrix divide operator / to an element-wise divide operator ./ with the dot.

circa 6 anni fa | 1

Carica altro