Answered
matlab code to make values of an array in specific ranges(index positions) equal to zero
for k=1:numel(start_index_positions) d(start_index_positions(k):end_index_positions(k)) = 0; end

10 years ago | 0

Answered
mxSetData to subset of mxArray
Not without a hack. The reason is as follows: The API functions mxSetPr, mxSetPi, mxSetData, mxSetImagData, mxSetIr, and mxS...

10 years ago | 1

| accepted

Answered
Why use ./ in x = ( (-1).^(n+1) ) ./ (2*n - 1)
Yes, you need to use .^ and ./ instead of ^ and / because at least one of the operands is not a scalar. If at least one of the ...

10 years ago | 1

| accepted

Answered
mxAddField/mxGetField with unicode name
_... Is it possible to work with structures using 2-byte wide characters? ..."_ If I understand your question, the answer is ...

10 years ago | 1

| accepted

Answered
Is there any way to speed up matrix multiplication if I only need a subset of the entries?
Just out of curiosity I coded up a mex routine to compare. The mex routine simply does naive dot products between rows & columns...

10 years ago | 1

Answered
Newton Raphon's Method - Help
I don't know why you would use all of the symbolic stuff inside your function (as opposed to just hard coding the derivative), b...

10 years ago | 1

Answered
Bisection Method Not Working
It is not clear to me that your initial guesses are even bracketing your desired tof. So there will be no hope that your bisecti...

10 years ago | 0

Answered
i have 186 brain mri 2d slices (256*215) i want to stack them into 3d array (256*215*186) ?
Type the following at the command line: dbstop if error Then run your code. When the error is encountered the code will ...

10 years ago | 0

Answered
How do I create a function that accepts a 3 element vector as input, but returns scalar values?
If I understand you correctly, here is an outline of such a function (in a file called sort3.m): % Filename sort3.m func...

10 years ago | 0

| accepted

Answered
accessing double arrays in a multidimensional array
e.g., A = your 256x256x1056 array B = mean(A,3); % <-- average of A over the 3rd dimension C = mean(A(1:50,1:50,:),3...

10 years ago | 0

| accepted

Answered
fast initialization of cell array of strings mex
So, sounds like you have a single array of char data in your C routine, with a second int array that contains start/stop locatio...

10 years ago | 1

| accepted

Answered
Why am I unable to plot all values in a for loop?
Rather than a loop, can you just do this? T = 0: 0.01: 0.2; V_1 = Voc_close + (V_0 - Voc_close).*exp((-T./2)./(Rt_close....

10 years ago | 0

Answered
How can I compare two strings with different size/length in MatLab?
E.g., assuming you just want to count total number of characters that are exactly the same: s1 = a string s2 = another s...

10 years ago | 0

| accepted

Answered
A way to extract values based on the value of their neighbor?
This picks off the items with a 1 to the left (in columns 1 or 3) for your 4-column example: G = [g(:,1:2);g(:,3:4)]; G ...

10 years ago | 0

Answered
How to write a function equation in matlab?
Here is a function assuming single values for x1 and x2, which would be stored in the vector x: % Assumes numel(c)==size(A,...

10 years ago | 0

| accepted

Answered
Complex roots equality problem
R2016b: >> rts=roots([16 -32 116 0 -100]) rts = 0.904997916303652 + 2.626226923351172i 0.904997916303652 - 2.6...

10 years ago | 0

| accepted

Answered
Problem in ode15s, undefined function for input arguments of type double
Try giving a function handle to oce15s instead of a character string file name. E.g., [t, q_i_1]=ode15s(@leading_vehicle, ...

10 years ago | 1

Answered
How can I set the arrays dimensions?
You can't "freeze" the size of native variables in MATLAB. They are free to change size at any time. (You could make an OOP clas...

10 years ago | 1

Answered
Exercise: Add 3 to just the odd elements of x=[2 5 1 6]
Create z = x and then modify the elements of z directly using the indexes contained in y. E.g., z = x; z(y) = z(y) + 3; ...

10 years ago | 0

| accepted

Answered
How can i add a prime counting function to this?
n = zeros(1,N); n(p) = 1; c = cumsum(n);

10 years ago | 1

| accepted

Answered
Divide a cell arrays with a part of another cell array
Try this: C = num2cell(bsxfun(@rdivide,cell2mat(A),cell2mat(B(1,2:end)))); Note that B{1,2:end} using the curly brac...

10 years ago | 0

| accepted

Answered
Raise elements of cell arrays in the power of 2
Like this? A = 2x100 cell array of scalars A2 = mat2cell(cellfun(@(x)x.^2,A),ones(1,2),ones(1,100)); SIDE NOTE: Yo...

10 years ago | 0

| accepted

Answered
How to define and call a function in the same script
Does it have to be a script? Can you simply wrap your script in a dummy function name? Then you could simply attach your other ...

10 years ago | 1

Answered
Subtract from a cell array of vectors a vector
Does this do what you want? A = 2x100 cell array of scalars B = 2x1 cell array of scalars C = mat2cell(bsxfun(@minu...

10 years ago | 0

Answered
How do I resize an mxArray
You are missing a step. After you do the mxRealloc, you need to set this new pointer into the mxArray. E.g., a = mxRealloc...

10 years ago | 1

| accepted

Answered
how to convert negative integers(that are not between -127 and 0) to binary in matlab?
What range are they in? E.g., for a 16-bit range: bitstream = dec2bin(typecast(int16(b),'uint16')); You've got numbers o...

10 years ago | 0

Answered
I got "Conversion to cell from double is not possible." on this line ERROR(:,i)=error; ,,,,any help please?!
"error" is the name of an intrinsic MATLAB function. Do you have a variable called "error" also?

10 years ago | 0

Answered
How to apply a function to an specific column of all variables?
Try this: eval([myvars{i} ' = data']);

10 years ago | 0

| accepted

Answered
Struct as input to mex file
You are passing in a 1x1 struct, so the only valid index inside a mex routine is 0 since the indexing is 0-based. So change thi...

10 years ago | 0

| accepted

Answered
I get "In an assignment A(:) = B, the number of elements in A and B must be the same." error when I execute the following code.
Do you need to index the sin(y) as as sin(y(n)) in this line: x(n+1)=(log(x(n)^2)-sin(y(n))+(3*x(n)/2));

10 years ago | 1

| accepted

Load more