Answered
index an array with arrays
I'm still not exactly sure what you are trying to do, but If data is 1D and you want to set all values between the indexes to so...

7 years ago | 0

| accepted

Answered
my code does not loop
You need to move your err initialization inside your loop. I.e., these lines need to move: iter=0; err=1; Also, you need to i...

7 years ago | 0

| accepted

Answered
Segmentation violation while running mex file
The first thing I noticed is the code is not robust against an input that is not exactly as expected. E.g., You don't check tha...

7 years ago | 1

Answered
how to read binary file generated by Fortran
Unformatted Fortran is not the same as stream binary. Whereas stream binary is just the data itself, unformatted Fortran has ex...

7 years ago | 0

Answered
Array indices must be positive integers or logical values.
At least two problems. First, you need to start your for loop indexing at 1 instead of 0: for i = 1: n-1 % ending at n-1 so tha...

7 years ago | 0

Answered
Element multiplication and subtraction
If you are unsure, then just put dots next to every * and / and ^ operation. If a scalar happens to be involved it will still wo...

7 years ago | 0

Answered
Use Euler's method for Mass-Spring System
I will get you started. Let y be a 2-element vector containing your states. Define y as follows y(1) is defined to be x ...

7 years ago | 1

Answered
Can looping values be used for indexing?
finalpop, and thus LLPmatrix, has a 0 value as one of its elements. You then use this as an index within the loop, which is caus...

7 years ago | 1

| accepted

Answered
how can i find the roots
You could wrap it in a loop. E.g., for I= 0:50 r = roots([0.013 -1*(0.013+I) I]); % do something with r here end

7 years ago | 0

Answered
How to modify a variable inside of a loop and use it outside the loop
What does this show: sum(times(:)>=800 & times(:)<900)

7 years ago | 0

Answered
what does this code represents? and why rand() has no value between parentheses?
rand() is the same as rand without the parentheses ... they both simply call the rand function with no input arguments. The beh...

7 years ago | 0

Answered
Solve 10 system of ODEs with separate functions and time dependent factors
This isn't going to work. You can't use random values in the derivative function for ode45. The derivative calls that ode45 mak...

7 years ago | 1

| accepted

Answered
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
What is size(dist) and size(v_e)? If these are row vectors, then maybe you need to do e*e' instead to get a scalar result.

7 years ago | 0

Answered
Loop through specific strcuture field names
As Stephen says, this is going to be slow. But maybe this syntax using dynamic field names would be useful to you: R{i}.([name...

7 years ago | 0

| accepted

Answered
Create new cell array based on entries of other cell arrays
Not sure if this will suffice for your needs, but a simple way to get the unique strings in alphabetical order: arr4 = unique([...

7 years ago | 0

| accepted

Answered
Normalizing a complex number
It is not clear what you are trying to do. You use the word "normalize" but it looks like maybe you are just trying to find the ...

7 years ago | 0

Answered
Which is more efficient: iteratively filling in a sparse matrix vs. creating a new sparse matrix every time i need to update the matrix?
Iteratively changing a sparse matrix causes the entire data set to be copied each time, so this is inherently not efficient and ...

7 years ago | 0

Answered
I have a matrix eg [1,6,3], and i have a 31*1 cell array ,each element of cell is a matrix. My problem is i wants to extract matrix from the cell position {1*1},{6*1},{3*1} and to be stored all these in separate matrices.
E.g., is this what you want? c = your 31x1 cell array v = your vector of indexes, e.g. [1,6,3] result = c(v); % extract the c...

7 years ago | 0

| accepted

Answered
Error was detected while a MEX-file was running and MATLAB is exiting because of fatal error
Can you explain what you intended with these lines for A: double **A; : A = (double**)mxGetPr(prhs[0]); If y...

7 years ago | 0

| accepted

Answered
inconsistency when comparing cell arrays with strings vs char array
This is a really good question. E.g., >> version ans = '9.4.0.813654 (R2018a)' >> strcmp("abcd","abcd") ans = logica...

7 years ago | 0

Answered
Voltage Measurement block: "do not delete this again". What is the story behind this?
Do not delete this "gain" ... not "again" P.S. Mathworks employees do have a sense of humor ... just not for this particular ca...

7 years ago | 1

| accepted

Answered
Array Indexing Logical Values
"We know that rounding the index prevents the error" So that's a big clue. "Is there a hidden decimal place not being shown to...

7 years ago | 0

Answered
Matlab crashes when i create output matrix in mex.
I haven't had much time to look at this in detail, but at first glance this stands out: void createTable(unsigned int *dataStre...

7 years ago | 0

Answered
hi everybody , i have a question please , if i have X=[1:10] and Y=[-5:5] and i want to have all the point of the plane (x,y) , what can i do in matlab to extract this point to use it
Does this do what you want? [x,y] = meshgrid(X,Y); result = [x(:),y(:)]; Then iterate over the rows of result. Or you can ju...

7 years ago | 0

| accepted

Answered
summation of sinx using summation
You are missing the alternating signs of the terms. E.g., you could put in a factor of (-1)^something to get this effect. The ...

7 years ago | 0

Answered
How to concatenate each row of a matrix into a vector ?
result = char(A+'0');

7 years ago | 1

Answered
Index exceeds the number of array elements (1)
Type the following at the command line: dbstop if error Then run your code. When the error occurs, the code will pause at that...

7 years ago | 0

Answered
How to correct "Parse" error
Don't have your function at the top of this. Put it at the end or in a separate file. E.g., t = 1; while (height ~=0) h =...

7 years ago | 0

Answered
I have a matrix (57,3600,45), how can I create matrices with (3600,45)?
Is this what you want? k = some integer index squeeze(your_matrix(k,:,:))

7 years ago | 0

Answered
Square root table without using arrays
You need to put the new line \n in appropriate places in your loops. In particular, you only need one new line \n printed once y...

7 years ago | 0

| accepted

Load more