Answered
how to select random columns?
If you want only one column at random: x = randi(size(data_sample,2)); column = data_sample(:,x); For more than o...

11 years ago | 3

| accepted

Answered
create a function that takes a matrix input, that gives output matrix of odd elements
Have a file called oddelements.m (or whatever name.m you pick), and in that file you would have this: % oddelements: (inser...

11 years ago | 1

| accepted

Answered
if an array like [.002 1.1103 0.665 .002]. how can i get [a b c a]?
Not sure what you want. Maybe this? myVector = [.002 1.1103 0.665 .002]; a = myVector(1); b = myVector(2); c = myV...

11 years ago | 1

Answered
Help with coding taylor expansion of sin(x)
Yes the code for sin(x) is similar to cos(x). You could Bing "Taylor Series for cos x" and click on the first link: http://ww...

11 years ago | 1

Answered
Converting 1x1 matrix into 200x1 with same value?
myVector(1:200,1) = singleValue;

11 years ago | 1

| accepted

Answered
error in c-compiler
Type the following at the command line. When asked if you want MATLAB to look for compilers, press Enter: mex -setup If ...

11 years ago | 0

Answered
Error using horzcat Dimensions of matrices being concatenated are not consistent. Please help.
Use the debugger to pause the code at the error. Then examine the dimensions of the variables involved and figure out what the p...

11 years ago | 0

Answered
How to eliminate rows with NaN elements?
rows = any(isnan(myMatrix),2); myMatrix(rows,:) = [];

11 years ago | 3

| accepted

Answered
How to do counter in matlab?
I am still guessing here. Maybe this is what you want? (I am assuming M is square) load M.dat t = 600; q = zero...

11 years ago | 0

Answered
Editing a function to return a value that shows how many times a recursive function is called
See this link: http://www.mathworks.com/matlabcentral/answers/195865-fibonacci-program-makes-matlab-go-busy-forever You co...

11 years ago | 0

Answered
Choose certain matrix elements from a matrix
You could use logical indexing for this. E.g., z = r < R; % Logical result for 1's locations z = z(:); % Turn into colum...

11 years ago | 0

Answered
what does inner matrix dimensions must agree matlab error?
This error can often be fixed by replacing the * operator (matrix multiply) with the .* operator (element-wise multiply). Look a...

11 years ago | 0

Answered
narginchk and varargin in MATLAB
narginchk(7, 7) throws an error if the number of input arguments is less than 7 or greater than 7 (i.e., the number of input arg...

11 years ago | 0

Answered
Give me an hint
Hint: doc find

11 years ago | 1

Answered
Optimize/speed up a big and slow matrix operation with addition and bsxfun?
Assuming you have a C compiler available, here is a simple C mex routine to do the calculation. Could possibly be sped up even m...

11 years ago | 0

| accepted

Answered
How to increase the precision in my output using structures
I would assume s(1).pixels is some type of integer class instead of double, so you are getting an integer result. Either convert...

11 years ago | 0

Answered
how to solve this question using two loops?
Big Hint: Suppose the grid is M x N. You've got (M+N) total moves to make, with M of them being "down" and N of them being "r...

11 years ago | 0

| accepted

Answered
How to plot multiple functions on one graph>
plot3 with hold on should have worked. That being said, looks like the last three cases have vo typos to me, since vo is all 0's...

11 years ago | 2

| accepted

Answered
load a file with 'dir'
You are getting the results of dir from a different directory than the current directory. I.e., you explicitly put the path in t...

11 years ago | 0

| accepted

Answered
Derivative of a Function
If you have the Symbolic Toolbox: >> g = @(x) exp(x^2-2) g = @(x)exp(x^2-2) >> syms x >> diff(g(x)) ans...

11 years ago | 0

| accepted

Answered
The plot for t and ssdot in the following code cannot be displayed as it shows a vector length mismatch. Please suggest how I can get around it...
Your loop is for i=1:n+1 So the last iteration increases the size of ssdot when this line is encountered: ssdot(1,i...

11 years ago | 0

| accepted

Answered
how to concatinate two array values in one array
A3 = [A1 A2];

11 years ago | 0

| accepted

Answered
How to determine the MATLAB version when compiling C/C++ mex files
After reconsidering the fact that I no longer have access to the many MATLAB versions that I used to (changed jobs), I realize t...

11 years ago | 3

Answered
Insert numbers of a matrix B in matrix A (only in odd indexes).
k = i + j; C = zeros(1,k); C(1:2:end) = A; C(2:2:end) = B;

11 years ago | 1

| accepted

Answered
How to determine the MATLAB version when compiling C/C++ mex files
mxCreateUninitNumericMatrix has been in the libraries for many years as an exported function, at least as far back as R2006 or s...

11 years ago | 2

Answered
Attempted to access x_set(:,100); index out of bounds because size(x_set)=[7600,1] help
Typically one would remove entire rows or entire columns if you want to preserve the 2D matrix. By removing individual elements ...

11 years ago | 1

Answered
Most efficient way to add multiple sparse matrices in a loop in MATLAB
Unless you know in advance the pattern of the non-zero spots and can exploit that, then I think you are stuck. At every iteratio...

11 years ago | 1

Answered
How to optimize this matlab code?
I assume you are trying to vectorize this for speed purposes. In your current code, the x(:,:,k) expression copies data, and the...

11 years ago | 2

Answered
Find the inear indices of a specific value in a 3d matrix using the positions of a 2d matrix
Another way: find(bsxfun(@and,A==2,B==1))

11 years ago | 2

Answered
Error using * inner matrix dimensions must agree
Most likely i is not a scalar, hence the error. Try stopping on the error and then examining the dimensions to see what is going...

11 years ago | 0

Load more