Answered
Get a subset of a structure array in mex
Here is some sample code to create a subset of a struct array inside a mex routine. One key point is that there are no official ...

10 years ago | 1

Answered
anybody can help me please..... how i can write this with plot ? x=0:1:5; y=-5x^3+3x^2-5;
Vectorize the operations using element-wise operations. E.g., x = 0:1:5; y = -5*x.^3 + 3*x.^2 - 5; % <-- Note the .^ in...

10 years ago | 0

Answered
combination of two matrices
A = 160 x 12 matrix B = 160 x 12 matrix Ar = reshape(A',40*12,[]); Br = reshape(B',40*12,[]); result = reshape([Ar...

10 years ago | 1

| accepted

Answered
I need an elegant and fast way to get elements by single index in matrix
m = size(A,1); V = A((1:m)'+m*(I-1));

10 years ago | 1

Answered
How can i flip specific bit of an binary array.
E.g., the bit in the (2,3) position: a(2,3) = ~a(2,3);

10 years ago | 1

| accepted

Answered
I am trying to sort three numbers without using inbuilt functions.What is wrong with the function?
Two of your branches do not set all three output variables. E.g., if p(1)<=p(2) if p(1)<=p(3) small...

10 years ago | 0

| accepted

Answered
Definite Integrals With Answer
For Part A, the instructor may want the answer in terms of x, not t. E.g. syms x disp(int(40-2*t,0,x)) % <-- Or disp(s...

10 years ago | 0

| accepted

Answered
mexPrintf to standard error
Brute force? I can't think of another way to get at the MATLAB standard error printing. E.g., /* Includes ---------------...

10 years ago | 0

| accepted

Answered
Making a matrix using colons or linspace working improperly within code
I suspect this is being caused by floating point round off error in the various calculations. Maybe just use a round in your lin...

10 years ago | 0

| accepted

Answered
find closest pairs in two datetime arrays with unequal length
Are the arrays sorted? Using sorted arrays, one could come up with a stepping algorithm. E.g., if you know that t2(k) < t1(i) ...

10 years ago | 0

Answered
Taylor and Euler Method for ODE
MATLAB is a 0-based indexing language. So you can't have y(0) in your code. It will need to start at y(1). y(1)= -0.25; ...

10 years ago | 0

| accepted

Answered
Coversion of visual c to matlab line
Rather than converting the code, you might consider a mex solution: https://www.mathworks.com/help/matlab/programming-interfa...

10 years ago | 0

Answered
How to pass parameters?
Not sure if this is what you want, but just pass them in: dX = -13.925*A*B*C*x + f(t,A,B,C); : function fval =...

10 years ago | 1

| accepted

Answered
Trying to graph each iteration of the for loop
You are plotting p(1,:) in the loop, but this never changes in the loop. Did you mean to plot pdot instead? E.g., plot(t,pd...

10 years ago | 0

Answered
4-D array to 3-D array
E.g., x = your 304 * 448 * 37 * 12 array y = reshape(x,304,448,37*12); Another possibility if you want those last two...

10 years ago | 0

| accepted

Answered
Error with matrix dimensions depending on which version of matlab i use.
Guessing that your friends are running R2016b and you are running an earlier version. In R2016b dimension mismatches such as thi...

10 years ago | 2

| accepted

Answered
Problem converting cell to string
If the individual cells can have more than two elements, e.g., U={[1,4],[1,5],[1,6],[2,4],[2,5],[2,6],[3,4,5],[3,5],[3,6,9]...

10 years ago | 0

Answered
Create a new field in a structure
Not sure if this is what you are really asking: mystruct.field1 = rand(1,3); % <-- Create a structure with field named fie...

10 years ago | 0

Answered
Weird!!!! Extremely simple question!! Can't assign values to first row of a sparse matrix, please help.
Typo. You used a small case 's' in that first row assignment. Change that to an upper case 'S' and everything will be as expecte...

10 years ago | 1

| accepted

Answered
A Few Key Concepts to Take From One Complete Program and Apply to Another Very Similar Second Computer Program from an Exponential Distribution with Lambda Function Applied..
I _*think*_ your question is how to generate exponential(lambda) random numbers. If so, you can get them from uniform(0,1) numbe...

10 years ago | 0

| accepted

Answered
How do I isolate a letter in some equation?
symvar is probably what you are looking for. E.g., >> eqn = '2=2*log(x).^2'; >> symvar(eqn) ans = 'x' EDIT...

10 years ago | 1

| accepted

Answered
How to limit user input to only one character?
Maybe this FEX submission by Jos is close to what you want: http://www.mathworks.com/matlabcentral/fileexchange/7465-getkey ...

10 years ago | 0

Answered
Matrix indexing multiple rows
x = your matrix result = x([2:4,5:8],:); % <-- pick off rows 2-4 and 5-8 Of course, the 2:4 and 5:8 could have been com...

10 years ago | 5

Answered
I need to compare two large arrays of data. Running is too slow, it takes 5 days to run the script below. Is it possible to run the script in less time? As?
Not a complete solution, but for starters I would suggest the following: Pull all of the data copying you do that does not de...

10 years ago | 0

Answered
How to repeat a for loop n times
Is this all you are trying to do? n = number of times to repeat the loop States = zeros(size(N,1)); for k=1:n ...

10 years ago | 0

| accepted

Answered
i want to make a for loop that goes like this for a=0:1:180 && 179:-1:-180 but it is not possible in matlab, any ideas how to do it?
It is not clear to me what you really want. Maybe this? for a=[0:1:180,179:-1:-180] % whatever end

10 years ago | 0

| accepted

Answered
need a help using loop
You have learned the hard way one of the first lessons of good programming practice ... don't create a bunch of variables with t...

10 years ago | 0

| accepted

Answered
How to confirm user input is a word based on ascii table?
Like this? prompt = 'Enter word '; while( true ) answer = input(prompt, 's'); if( all(ismember(answer,'AB...

10 years ago | 0

Answered
Question about machine epsilon
The short answer is that the result is rounded. How this rounding takes place is going to depend on the rounding modes available...

10 years ago | 2

| accepted

Answered
Improve efficiency of backslash operator for sparse matrices
You might find something in Tim Davis FEX submissions that would help: http://www.mathworks.com/matlabcentral/fileexchange/?t...

10 years ago | 0

Load more