Respondida
How to set specific size of a figure with exportgraphics?
This doesn't answer your question about controlling exported sizes, but you might be interested in the following export_fig FEX ...

más de 3 años hace | 0

Respondida
Renaming the variabel while Symbolic to function handle conversion with matlabFunction
You could keep your existing code and create another function handle: funcv = @(A,xdata,ydata)func(A(1),A(2),xdata,ydata)

más de 3 años hace | 0

Respondida
Making an Array out of another Array if conditions are met
You don't need a for-loop for this. The best way is to use logical indexing. See this link: https://www.mathworks.com/help/matl...

más de 3 años hace | 0

| aceptada

Respondida
How to remove February 29th for leap years in a daily time series over 43 years?
To get rid of the leap days, you can use evenly spaced indexing since the number of days between leap days is constant for your ...

más de 3 años hace | 0

Respondida
I would like to write a for loop to store all values of y when A=1,2,3,4,5. into a variable y1,y2,y3,y4,y5 respectively. Any help will be greatly appreciated. Thanks
No loop needed, and no need to create multiple variables to hold results. Just use implicit array expansion and hold results in ...

más de 3 años hace | 0

| aceptada

Respondida
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Looks like you changed the definition of what f_m is in your code. In these lines f_m appears to be an array intended to hold va...

más de 3 años hace | 1

Respondida
What does A(2:4) = [ ] do if A is a 3x3 matrix?
This is linear indexing. Even though the variable is a 2D matrix, MATLAB allows you to index into it using only one index. The l...

más de 3 años hace | 1

Respondida
error using function code
Create a file called lettergrade.m somewhere on the MATLAB path (e.g., in your working directory) edit lettergrade.m Copy all ...

más de 3 años hace | 0

Respondida
dynamic naming of structures
Would it be acceptable to use x as a dynamic fieldname instead of the top level variable name? E.g., v.(x).a v.(x).b

más de 3 años hace | 1

Respondida
How can I define an array of sparse matrix? (both for GPU and CPU)
For CPU, you can use the ndSparse submission by Matt J on the FEX: https://www.mathworks.com/matlabcentral/fileexchange/29832-n...

más de 3 años hace | 0

| aceptada

Respondida
numerical integration with recursive trapezoid rule
Some issues are immediately apparent. First, you don't reset S=0 inside the while loop. Isn't S supposed to contain only the a...

más de 3 años hace | 0

Respondida
Store every N columns in a Matrix to a new Matrix
Don't create a bunch of new matrices with hard to use names downstream in your code. Instead, simply reshape your matrix and the...

casi 4 años hace | 0

| aceptada

Respondida
MEX file always crashes when I run it
In the MATLAB code you have this: np=single(np); Then inside the Fortran gateway routine you have this: mwPointer xr, yr, n ...

casi 4 años hace | 1

| aceptada

Respondida
How can I reshape a matrix this way
a=[-0.26,0.23,0.033,0.1,-0.39,0.30;0.30,-0.39,0.10,-0.26,0.03,0.23;-0.03,-0.13,0.16,0.33,-0.16,-0.16] b=[-0.26,0.23,0.033;0.1,-...

casi 4 años hace | 0

| aceptada

Respondida
Matlab while loops with equations
You should probably go through the online tutorials for learning MATLAB. But I will give you an outline to get started: toleran...

casi 4 años hace | 0

Respondida
i need to find error in code because I it's increasing but it should be decresing
You need to use all the derivatives at the first point to propagate for the initial guess at the second point. I.e., these lines...

casi 4 años hace | 0

Respondida
t = 2 s, i = √−1, and 𝜔=120π rad/s. Evaluate the following using MATLAB? Hint: exp(n) is used in MATLAB to evaluate en. (a) e−2𝑡𝑐o𝑠 (𝜔𝑡)
I am guessing that the original expression shown is supposed to be interpreted as: Then take the hint at how to evaluate the ...

casi 4 años hace | 0

Respondida
Why is my projectile motion code only working at certain input angles.
Drag depends on current velocity, not initial velocity. So you need to recalculate V at each step. E.g., Vx = Vx_new; Vy = Vy_...

casi 4 años hace | 0

Respondida
Sine equation in Euler Method ODE
You've only got one scalar differential equation, so I don't understand why you think you need two variables x and y along with ...

casi 4 años hace | 0

Respondida
subtract matrix from vector
Just learn how to use indexing and element-wise operators. From your language, here are the pieces: subtract - the first thre...

casi 4 años hace | 0

| aceptada

Respondida
How can I create arrays with different names using loop?
Don't embed numbering into the variable names. This will make the variables hard to use downstream in your code. Use cell arrays...

casi 4 años hace | 0

Respondida
How to subtract each column of a matrix from a column vector?
Just do a usual subtraction and let MATLAB implicit expansion kick in: M = your matrix v = your column vector result = v - M;...

casi 4 años hace | 0

Respondida
Simple mex file crash?
You need to create the output variable yourself. plhs[0] doesn't exist until you create it, thus this line crashes: outData = m...

casi 4 años hace | 0

Respondida
Simulating Projectile with Matlab
You don't show us both methods (with and without drag) so we can't compare them. I presume you simply set k=0 for the case witho...

casi 4 años hace | 1

| aceptada

Respondida
Matlab simulation for planet motion
The initial condition for position and velocity need to be outside the loop, prior to loop entry.

casi 4 años hace | 1

| aceptada

Respondida
Vector ODE solution is not periodic/ as expected
This index 4 dxdt(4) = -DU^2* x(3)/sqrt(x(1)^2+x(2)^2+x(3)^2)^3; needs to be index 6: dxdt(6) = -DU^2* x(3)/sqrt(x(1)^2+x(2)^...

casi 4 años hace | 0

| aceptada

Respondida
How to compile a Fortran subroutine by using the MEX engine
It looks like you are taking input, calling a MATLAB function, and getting output from that function. I still say it would be ea...

casi 4 años hace | 0

| aceptada

Respondida
How to create Matrix [1 2 3 4; 2 4 6 8; 3 6 9 12; 4 8 12 16] without using loops or any functions using loops?
n = 4; % whatever result = (1:n) .* (1:n)' % use implicit expansion row .* column

casi 4 años hace | 2

| aceptada

Respondida
Vectorising Multiplying each column from a matrix with a square matrix and the tranpose of this column
If you need the same column on each side of the multiply, then maybe this: result = sum(h'*Pn.*h',2);

casi 4 años hace | 1

Respondida
Problem in using mxSetPr with USHORT
To attach pointers of type other than double to an mxArray, you can use the mxSetData( ) function as Jan suggests. In your case ...

casi 4 años hace | 1

Cargar más