Answered
Rearrange matrix into single row
result = reshape(b.',1,[]); The transpose is needed to get the row values to line up in memory first before doing the resha...

7 years ago | 2

Answered
Why do I have 2 outputs instead of 1
The comma in MATLAB is a separator (i.e. forms a "comma-separated-list"), not a decimal point. So typing in 0,1 is equivalent to...

7 years ago | 0

Answered
Is it possible to iteratively increase a number within the middle of a file name?
E.g., using sprintf n = some integer sprintf('Myfilename%dwith%dand%dstuff',n,n,n) Sample run: >> n = 5; >> s...

7 years ago | 0

| accepted

Answered
Subroutine functions in MatLab
Create a file with the following name: init.m Put your code into this file, e.g., function stuff = init stuff = what...

7 years ago | 0

Answered
How to calculate argument max for a vector
Assuming "arg max" means index of the max location, use both outputs of the max function p = your vector [m,x] = max(p);...

7 years ago | 0

| accepted

Answered
How to change values of elements in a sparse matrix
Not sure what your problem is. Sparse matrix elements can be changed directly just like full matrices. E.g., F = your full ...

7 years ago | 1

| accepted

Answered
Largest value of x such that 2^(-x)>0
If you are talking about the numerical range of IEEE floating point numbers, then the answer depends on the specific bit formatt...

7 years ago | 0

Answered
Calculate weighted average of a 2D matrix
E.g., w = 1x481 vector of weights M = your 376x481 matrix of values result = sum(M.*w,2) / sum(w); or sum(bsx...

7 years ago | 0

| accepted

Answered
Incorrect matrix computation: a*inv(a) does not produce the identity matrix
The "a" matrix you are using is not full rank and does not have an inverse. That is what the warning message is trying to alert ...

7 years ago | 0

| accepted

Answered
MEX question: How to set scalar and array values within plhs[0] struct?
mxGetField returns a pointer to mxArray, not pointer to double. You need to get at the data with the appropriate function. E.g.,...

7 years ago | 0

Answered
Changing elements of an array by row and column using for loop?
You should probably be using size(alpha,1) and size(alpha,2) instead of length(alpha) and size(alpha) in your looping. And you n...

7 years ago | 0

| accepted

Answered
how to use for loop for below.
This line function area = areaCircle(r) means the function input is r and the output is area. So you need to assign the ...

7 years ago | 0

| accepted

Answered
Numerical instability of acos
Since you don't show us any code so that we can see where these "funny" values might be coming from, I can only point you to thi...

7 years ago | 0

Answered
How to separate M*3 matrix by interval of 1
E.g., maybe something like this? data = your 20x3 matrix x = data(:,1); result = data( 0<x & x<1 ,:);

7 years ago | 1

Answered
Initialize a field in all elements of a struct array
Another way using deal: [a(1:numel(a)).field2] = deal(4);

7 years ago | 1

Answered
Calculation of Factorial using Recursive Relation
You need the proper formula first: y = n * recursion(n-1); But also you need to figure out how to stop the recursion and...

7 years ago | 0

| accepted

Answered
How to find value of x such that 2^(-x) =realmin
Just solve your equation directly: x = -log2(realmin) Note that realmin is for the smallest normalized number. Denormali...

7 years ago | 2

Answered
Problems with complex output in mex funtion
E.g., just using the definitions in the MATLAB doc: mxComplexInt16 *buf_prueba; : plhs[2] = mxCreateNume...

7 years ago | 0

Answered
Finding a 3D parallel vector
A unit vector parallel to the points from (a,b,c) to (d,e,f) is just this: v1 = [a,b,c]; v2 = [d,e,f]; u = v2 - v1; ...

7 years ago | 2

| accepted

Answered
Obtain maximum value of variable over multiple iterations?
E.g., you could add a variable to your looping for this: altmax = -inf; % your loop start % stuff that calculates...

8 years ago | 0

| accepted

Answered
How to delete elements from a struct array?
Not exactly sure what you want to do. If you want to delete all structure elements (i.e., all fields for that element) where the...

8 years ago | 2

| accepted

Answered
Built in Julian Date Converter not working?
What version of MATLAB are you using? juliandate was introduced in R2014b. Are you using an unsupported class variable as one of...

8 years ago | 0

Answered
I want to convert a 4x1 vector column to skew symmetric matrix in matlab
You could just use the code you have already typed above. E.g., a = Q(1); b = Q(2); c = Q(3); d = Q(4); S = [0 -a d ...

8 years ago | 0

| accepted

Answered
How to get a pointer to 2D array when writing a C source Mex file?
You can't use the [j][i] indexing syntax with the pointer returned by mxGetDoubles. You would need to set up a separate pointer ...

8 years ago | 1

| accepted

Answered
Adding a singleton dimension to a 2D vector
There is no way to force a variable to physically store trailing singleton dimensions past the 2nd dimension. Operations that na...

8 years ago | 2

Answered
Why am I getting this error message?
Don't post images of code. This makes it impossible for readers to copy & paste your code for testing. Instead, post the actual ...

8 years ago | 1

| accepted

Answered
Doubt about matrices mxm
See the following link: <https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dy...

8 years ago | 0

| accepted

Answered
Why doesn't the less than operator work inside a for loop for decimals
Floating point arithmetic effects. See this link for starters: <https://www.mathworks.com/matlabcentral/answers/57444-faq-wh...

8 years ago | 2

| accepted

Answered
Exist function returning 0 for a variable that definitely exists?
Don't use exist() with struct field syntax. Only use it for variable names. E.g., >> a.f = 4 a = f: 4 >> exis...

8 years ago | 2

| accepted

Load more