Answered
New to matlab, need help with problem..
Good start. Thank you for posting your code. Some help: - Have the top value of your loop be 300, not 299 - Have the Tot...

8 years ago | 0

Answered
Can one run a matlab script from the command line and pass arguments to it **without making it into a function**?
You could have your script use the getenv( ) function to retrieve all of those environment variables (as strings). Or have your...

8 years ago | 0

Answered
how can I create help product for my function in matlab?
Put all of your help text in comments at the top of the file. E.g., here is a file called mycube.m % MYCUBE Calculates the...

8 years ago | 0

Answered
Repeating a row vector in MATLAB until it reaches a specified length.
result = k(mod(0:numel(j)-1,numel(k))+1);

8 years ago | 0

Answered
Result as a vector
Use element-wise divide operator with the "dot", ./ vx1 = (0.287*Tx1)./Px1;

8 years ago | 0

| accepted

Answered
find the position of en element if you have the increment
You need to be careful how you search for this element. Because of the way the colon operator works with floating point fractio...

8 years ago | 0

Answered
How to concatenate matrices using for loop?
If x is a cell array, and you simply want all of them, then result = cell2mat(x); or if you want them stacked vertically...

8 years ago | 0

| accepted

Answered
How to find the corresponding vector?
Dist = zeros(1,n); Distx = zeros(n,numel(x)); % <-- ADDED, allocate for saved x vectors for k=1:n xp = randperm(...

8 years ago | 1

| accepted

Answered
Need to modify function handle output when a function is within the function handle
E.g., you could use another function handle to pick off the element you wanted. sim4end = @(x)x(4,end) Then your result ...

8 years ago | 0

| accepted

Answered
Modify element in a matrix, row vector
rowvector(rowvector>=0 & rowvector<=500) = 0;

8 years ago | 0

Answered
How to sum the results of a loop?
E.g., for generic x s = sub2ind(size(d),x(1:end-1),x(2:end)); Dsum = sum(d(s)); If you always wanted to sum the super...

8 years ago | 0

Answered
How can I find all possible combiantions of 3 numbers in a 6 number array using a for loop?
Assuming your instructions are to use nested loops and that you need to pull exactly three elements, the looping is fairly strai...

8 years ago | 0

Answered
How do I generate a uniform random number from a 2d matrix to form a 3d matrix
E.g., later versions of MATLAB: A = whatever; f1 = 0.8; f2 = 1.2; n = 5000; B = A .* (f1 + rand([size(A) n])*(f...

8 years ago | 0

Answered
how to place zeros instead of blanks in array
If you really mean blank spaces, then e.g. B(B==' ') = '0';

8 years ago | 0

| accepted

Answered
How to find the number in a vector that is most common and get the index
result = find(a==mode(a)); If there is more than one number that ties for "most", the above will only find the first such o...

8 years ago | 0

Answered
Acessing fields of a structure
Assuming your struct is multi-element, with each element having a username and a password. One way, which first converts the us...

8 years ago | 0

Answered
About preallocating for speed
This depends on what the size and class of the matrix returned by build_matrix( ) is. E.g., suppose it returns an MxN double ma...

8 years ago | 0

| accepted

Answered
Is it possible to create a sub-array without using additional memory on Matlab?
What you are attempting to do creates an invalid mxArray. That is, the data pointers of an mxArray *must* be known by the MATLA...

8 years ago | 1

Answered
Why i am getting Error using * Inner matrix dimensions must agree.
Type the following at the command line: dbstop if error Then run your code. When you encounter the error, the code will...

8 years ago | 0

Answered
MATLAB using .m file in preference to .mexw64
Either: - Put the .mexw64 file in the same directory as the associated .m file Or: - Make sure the directory where the ...

8 years ago | 0

| accepted

Answered
A sparse matrix vector multiplication in C mex programming
Here is the bare bones C code for this. Most of the code consists of argument checking etc. The actual computation part of the...

8 years ago | 2

| accepted

Answered
How to access array element from vector of its entries
One way: c = num2cell(v); result = A(sub2ind(size(A),c{:}));

8 years ago | 0

| accepted

Answered
solving odes (resiscted 3 body problem)
Building matrices with [ ] can be picky when it comes to spaces. E.g., >> [1;5-3;4] ans = 1 2 4...

8 years ago | 0

| accepted

Answered
Array multiplication along certain dimension?
Another way: B = sum(bsxfun(@times,A,reshape(V,1,1,1,numel(V))),4); Or in later versions of MATLAB: B = sum(A.*resh...

8 years ago | 0

Answered
Adding zeros to a matrix to match the dimensions of two matrices.
Another way: newA = zeros(size(B)); newA(1:size(A,1),1:size(A,2)) = A;

8 years ago | 2

Answered
Is it possible to do an in-place mxCalloc at a specific address, like "placement new"?
You cannot attach memory allocated from native C/C++ functions to an mxArray. Period. It will result in an assert seg fault. ...

8 years ago | 1

Answered
splitting matrix using while loop
Hint, if x is your data then x(1:100) will be the first part, x(101:200) will be the second part. Etc.

9 years ago | 0

Answered
Dice roll, how to write if statement for not 6 or 1?
E.g., if all(ismember(x,2:5))

9 years ago | 2

Answered
what is the problem of this function code?
The reason you are getting the error is because you change the size of the grades variable within the loop, so the last index(es...

9 years ago | 0

| accepted

Answered
how can i delete the extracted rows from the original matrix ?
x = M(:,15)<6; % Remember the logical indexes of the rows Tand= M(x, :); % this is the extracted one with 400*15 dimension...

9 years ago | 0

| accepted

Load more