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 ...

9 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...

9 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...

9 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...

9 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....

9 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...

9 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 ...

9 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,...

9 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...

9 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, ...

9 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...

9 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; ...

9 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);

9 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...

9 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...

9 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 ...

9 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...

9 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...

9 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...

9 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?

9 years ago | 0

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

9 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...

9 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));

9 years ago | 1

| accepted

Answered
bsxfun with AND condition
Assuming q{x,y} and compare# are different sizes and need bsxfun, just & the two separate calculations: result = bsxfun(@lt...

9 years ago | 0

| accepted

Answered
How do I fix my code to produce ones along the reverse diagonal?
Yet another way using linear indexing: I = zeros(n); I(n:n-1:end-1) = 1;

9 years ago | 3

Answered
Which of these two assignments is more efficient
Another method to try that might be faster for your application: %% (3) or is this faster c_mem(1:end-1)=c_mem(2:end); ...

9 years ago | 0

Answered
While loop will not stop running?
You are corrupting the value of k and not doing the term summing properly. These lines: k=1/(k+1)^2; term=sum1+(1/(k...

9 years ago | 0

| accepted

Answered
Why this error is showing?
You can get allcomb, written by Jos, from the FEX here: http://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb-var...

9 years ago | 1

| accepted

Answered
For Loop for storing data
No loop needed: a = your very large matrix b = a(:,1:6:end); % every 6th column, starting with 1st column

9 years ago | 0

Load more