Answered
Create array with same number
See this link for a discussion of various methods to do this: <https://www.mathworks.com/matlabcentral/answers/51411-initiali...

7 years ago | 6

| accepted

Answered
thread safety of mx mex functions
Here is my short novel on this topic ... To understand how dimensions are stored in mxArray variables, it will help to review...

7 years ago | 3

| accepted

Answered
Create a For Loop
Simply adjust your expectations of how to use indexing. E.g., let S(1) mean the same thing as S0 S(2) mean the same thin...

7 years ago | 0

| accepted

Answered
What does "Error: ()-indexing must appear last in an index expression" mean?
You need to use multiply operators between the ( ) expressions to multiply them. MATLAB does not do this automatically. E.g., ...

7 years ago | 0

| accepted

Answered
how can i generate a random number between two float numbers
This is one of the examples in the rand doc: val = mnval + rand*(mxval-mnval);

7 years ago | 1

| accepted

Answered
Is there a faster way to change zeros to ones and ones to zeros?
Assuming you have *only* 0's and 1's in your array, here is another way that also keeps the class of the result as uint8: A...

7 years ago | 3

Answered
A fast way to perform sparse matrix-free product with a vector
Assuming the vectors are 3-tuples of row, column, and value, and that all of the variables involved are full double vectors, her...

7 years ago | 1

| accepted

Answered
How do I make a function?
You can use a function handle for this. E.g., F = @(n) P*(1+i).^n I'll leave it to you to plug in appropriate values an...

7 years ago | 0

Answered
Populating values across a cell
There is nothing in your loop body that uses the index pp other than the data_pro{pp} assignment, so every data_pro{pp} is going...

7 years ago | 0

| accepted

Answered
[1 1 2 2 3 3] --> [11 22 33]?
Start with this outline: x = your initial variable of values [m,n] = size(x); result = zeros(___,___); % <-- you fil...

7 years ago | 0

| accepted

Answered
Mex inplace change problems R2015b and later
One potential workaround is to change an element of the variable after the assignment to force a deep copy. E.g., >> x = 1...

7 years ago | 1

Answered
Undefined reference to mexPrintf for simple helloworld program
Your code is a standard mex routine that can be compiled and run at the MATLAB command line prompt as follows: mex hellowor...

7 years ago | 0

Answered
Newton Raphson equation trig functions
Instead of doing all of this as symbolic, it would probably have been simpler to use function handles and work in double. That b...

7 years ago | 0

| accepted

Answered
Assembly of matrices using for loop
Read each individual file into a cell array element, then vertically concatenate the cells all at once.

7 years ago | 2

| accepted

Answered
Cross Product is Returning Values way to small to be right
Your vectors are parallel to each other, so the answer *should* be 0. The small number you are getting is just from floating po...

7 years ago | 1

| accepted

Answered
Angle between 2 quaternions
Assuming these represent attitude rotations from one coordinate frame to another, if you are simply asking what is the minimum r...

7 years ago | 1

Answered
I want to make a programming function in which I want to take input any mathematical function like f(x)=sin(x)+x^2. then I take a input x and my function return a value of f(x).but i don't know how can i do?
E.g., s = input('Input a function of x: ','s'); f = str2func(['@(x)' vectorize(s)]); Now you have a vectorized functi...

7 years ago | 0

Answered
mexGetData() outputs zeros
1) Your check on prhs[1] requires that it is a double, but your pointer is to a float. So that mismatch will never work. f...

7 years ago | 0

Answered
How to pass a 3d array double[][][] from java to a Matlab function
As long as it arrives as a 3D variable but the dimensions seem backwards, perhaps you only need to permute it. E.g., x = 3D...

7 years ago | 0

| accepted

Answered
In MEX, how do I populate an array within a struct within plhs?
I don't have MATLAB or a C compiler handy at the moment, but here are some suggestions: 1) Don't make assumptions with API fu...

7 years ago | 0

Answered
Do two instances of MATLAB share a workspace?
Just open up two different instances of MATLAB ... they will be two separate processes with two completely independent workspace...

7 years ago | 3

Answered
Sparse matrix and savings
I don't fully understand your pseudo code, particularly your use of value when indexing into Pattern_Matrix(value). If you just ...

7 years ago | 0

| accepted

Answered
Query regarding a sparse complex matrix
The minimum data storage requirement formula for a double m x n sparse matrix with nnz non-zero elements, including the index da...

7 years ago | 0

Answered
Concatenate dynamical variables [A1;A2;A3.A4;AN) in one script line
Best advice is to back up and rewrite the code that is creating these A1, A2, etc variables in the first place. Instead, use som...

7 years ago | 1

Answered
Matrix is singular to working precision.
If a square matrix has rows or columns that are very nearly the same, then yes this would cause the matrix to be singular to wor...

7 years ago | 0

| accepted

Answered
How Can I solve a system of eight exponential equations?
E.g., h = 0:7; A = bsxfun(@(x,y)exp(x*y*pi*1i/8),2*h',h); % Form your equation matrix y = [0.2165 0.8321 0.7835 0.582...

7 years ago | 0

| accepted

Answered
How to construct a customized outer function for 2 vectors?
Start with a vectorized function handle, e.g., f = @(x,y)x.^y Then use bsxfun, e.g., result = bsxfun(f,A,B); Not...

7 years ago | 0

| accepted

Answered
How to pass equation to a function where the function subplots graphs?
y_exact_overdamped is a function handle. You pass that into your function which gets it as y_exact. You then assign this to y1. ...

7 years ago | 0

Answered
ToFile from SImulink read into C++ standalone program
Time series objects are classdef OOP objects. To get at the underlying data in them, you will need to use the mxGetProperty API ...

7 years ago | 0

Answered
Storing a vector in a loop each time with a different name
This is not the best way to do this in MATLAB. There are many, many posts on this site explaining why. Instead, you should use c...

7 years ago | 0

| accepted

Load more