Réponse apportée
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...

plus de 4 ans il y a | 0

Réponse apportée
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;...

plus de 4 ans il y a | 0

Réponse apportée
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...

plus de 4 ans il y a | 0

Réponse apportée
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...

plus de 4 ans il y a | 1

| A accepté

Réponse apportée
Matlab simulation for planet motion
The initial condition for position and velocity need to be outside the loop, prior to loop entry.

plus de 4 ans il y a | 1

| A accepté

Réponse apportée
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)^...

plus de 4 ans il y a | 0

| A accepté

Réponse apportée
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...

plus de 4 ans il y a | 0

| A accepté

Réponse apportée
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

plus de 4 ans il y a | 2

| A accepté

Réponse apportée
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);

plus de 4 ans il y a | 1

Réponse apportée
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 ...

plus de 4 ans il y a | 1

Réponse apportée
Beginner coding; my second, simpler approach at trying to make all elements distinct.
FYI, to generate random integers you can use the randi( ) function instead of ceil(value*rand( )): https://www.mathworks.com/he...

plus de 4 ans il y a | 0

Réponse apportée
How to make a "page transpose" in a 3D matrix without using the function pagetranspose?
Mtranspose = permute(M,[2 1 3]);

plus de 4 ans il y a | 2

| A accepté

Réponse apportée
How to multiply an inverse matrix (nxn) by an array (nx1) using for loop
Not sure why you have a for-loop at all. Maybe you can explain this. If you just want to multiply the explicit inverse by a vect...

plus de 4 ans il y a | 0

Réponse apportée
Adding numbers to an array
You don't really need both h and hnew. Just use h and some indexing. E.g., h = zeros(1,45); % allocate expected result k = 1; ...

plus de 4 ans il y a | 0

| A accepté

Réponse apportée
rounding issues in matlab, need to force values to 0
Instead of if abs(y1)< 1e-6 y1=0; end try y1(abs(y1)<1e-6) = 0;

plus de 4 ans il y a | 2

| A accepté

Réponse apportée
why will the area only work for the circle and not the other shapes
To compare strings, do not use the == operator which does an elementwise compare. Instead, use a function meant for comparing st...

plus de 4 ans il y a | 0

Réponse apportée
if loop error in MALAB
Change your test to if isempty(n)

plus de 4 ans il y a | 0

| A accepté

Réponse apportée
Index exceeds number of array elements
I think you want this for i = length(t)-1 to be this instead for i = 1:length(t)-1 The way you have it currently coded, ...

plus de 4 ans il y a | 1

Réponse apportée
Calling a Matlab function in Fortran
You have two fundamental errors with this code. You do not use the correct variable type for my_x, and you cannot call mexCallMA...

plus de 4 ans il y a | 0

Réponse apportée
MATLAB's inefficient copy-on-write implementation
See Loren's Blog on this topic. Basically, to write functions that can modify a variable "inplace" you need to call that functio...

plus de 4 ans il y a | 1

| A accepté

Réponse apportée
How to multiply one array to all elements of a vector with a different size?
You can use implicit expansion with the element-wise multiply operator: c = a .* reshape(b,1,1,[]);

presque 5 ans il y a | 0

Réponse apportée
sprintf, round-off, floating point bug?
I don't have all the versions installed necessary to investigate all of the results posted above, but this may simply be a "ROUN...

presque 5 ans il y a | 0

Réponse apportée
how to save a figure plotted with matlab with best quality in .ppt or .pdf file?
See this FEX submission by Yair Altman: https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig?s_tid=srchtitle ...

presque 5 ans il y a | 0

| A accepté

Réponse apportée
how to read and write half precision arrays via mexFunction
Very unfortunately, MATLAB has implemented the half precision data type as an opaque classdef type instead of a simple numeric t...

presque 5 ans il y a | 0

Réponse apportée
how to write mex function when input is a matlab function
This can be done, but it will not be efficient. The basic problem is that C/C++ doesn't understand anything about MATLAB functio...

presque 5 ans il y a | 0

Réponse apportée
Is it possible to process the sparse matrix faster with vectorization instead of for loop?
You need to re-evaluate how you are doing things. In the first place, you have the Euclidean calculation wrong. It should be thi...

presque 5 ans il y a | 0

Réponse apportée
How to exchange data between two C++ MEX files
Your current scheme is not foolproof. How does the 1st mex function know when it is safe to unlock and clear memory? How does th...

presque 5 ans il y a | 0

| A accepté

Réponse apportée
How to solve Lc=y without backslash operator?
First, I am assuming there is a typo and the system you are solving is Ly = c, not Lc=y. Second, you made a good start by writi...

presque 5 ans il y a | 0

Réponse apportée
I am using euler's method to solve a differential equation, but when I run the code it doesn't plot.
Take a look at these lines: t0=0; %start time t1= 500; %finish time dt = 100000; Your stepsize is much larger than the total...

presque 5 ans il y a | 1

| A accepté

Réponse apportée
Accessing struct using C library always NULL
Typically, it is best just to post your code so we can see exactly what you are doing, instead of posting a description of your ...

presque 5 ans il y a | 1

| A accepté

Charger plus