Interpolating arrays with different vectors [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have multiple arrays that I need to identify and interpolate to a set number. the set number will be the 'length?' of the biggest array. I need to How could I identify each array length and create a loop to interpolate each array to that specific length? Sorry if I am not providing enough detail.

A = rand(10,2);
B = rand(20,2);
C = rand(5,2);
%find max length, for you cell array you want: max(cellfun(#(x) length(x), MyCellArray))
n = max([length(A), length(B), length(C));
%repeat for each, i.e. loop through the cell array
x = A(:,1);
y = A(:,2);
m = min(x);
M = max(x);
d = (M - m) / n;
xi = m:d:M;
Ai = interp1(x, y, xi);

Related

Filter coefficients in matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm learning about signal processing and currently I have to do an speech synthesizer in Matlab. For emulate the resonator system of the mouth I've this transfer function:
R(z) = 1 - z ^(-1)
Can I implement this system with filter function in Matlab? I don't know how to extract the coeficients "a" and "b"...
Note: y = filter(b, a, x), where x is the input signal that we have to filter.
Thank you all!
Consulting the documentation for filter, you represent a transfer function as a rational function of coefficients such that:
The desired transfer function you want, Y(z) / X(z) = R(z) is equal to:
R(z) = 1 - z^{-1}
Here a(1) is implicitly equal to 1. Therefore, b(1) = 1 and b(2) = -1 referring to the above equation. All of the coefficients in the denominator are 0 except for a(1) which is equal to 1.
As such, a = 1; b = [1 -1]; and so filtering your signal is simply:
a = 1; b = [1 -1];
y = filter(b, a, x);
x is the signal of interest you want to filter.

finding all factors of a number [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am new to Matlab and for the values of a, l and w i need to find all the values for l in the data set and the corresponding w values.
a=10;
l=(0:10)
w=(0:10)
for l,d
if a == l.*w
disp(l)
disp(w)
end
end
Not sure what you want to do, but I think your code could be put as follows:
a = 10;
l = 0:a; %// actually, it would suffice to check numbers up to floor(a/2)
ind = rem(a,l)==0; %// logical index that tells if remainder is zero or not
disp([l(ind); a./l(ind)])
Result:
1 2 5 10
10 5 2 1
You could do it more directly with Matlab's factor function:
f = factor(a);
disp([f; a./f])
Result:
2 5
5 2

how can I make the index of a matrix increment in this function in matlab [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have a matlab function to detect the index array that has data below threshold
the result index_list will be in n x 2 matrix where
index_list(i,1) = row
index_list(i,2) = column
that have element array < threshold
Since I don't know how many result would be in index_list
function [index_list] = pickindex(Array,Threshold)
index = 1;
for i= 1:size(Array,1)
for j = 1:size(Array,2)
if(Array(i,j) <= Threshold)
index_list(index,1)=i;
index_list(index,2)=j;
index = index +1;
end
end
end
This code is working but is there any other suggestion to improve the code?
That sounds like the same thing as:
[r, c] = find(Array <= Threshold);
index_list = [r, c];

How to find locations of an element in a matrix [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a matrix A, that some elements of this matrix is repeated. I need to find locations of an
element in this matrix. How can I do this?
Thanks.
The function find can give you the row-column indices of elements.
For example
>> [r c] = find( A == 3 )
I hope it will help. Syntax
ind = find(X)
ind = find(X, k)
ind = find(X, k, 'first')
ind = find(X, k, 'last')
[row,col] = find(X, ...)
[row,col,v] = find(X, ...)
Link:
http://www.mathworks.in/help/matlab/ref/find.html
I see you have already got some answers on how to find elements.
Here is how to deal with duplicate elements.
First of all you can find the unique elements:
v = [1:4 2:5] % Suppose this is your vector
[v_unique, idx] = unique(v,'first')
v_unique is now your vector with duplicates removed. However, if you are interested in the locations of the duplicates, this will give you a list:
setxor(idx,1:numel(v))

how get the index of the minimum element of each row of matrix in MATLAB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am attempting to write a code to find index of the minimum element of each row from the 'distance' matrix, excluding zeroes from the matrix.
If the distance matrix is a (large) sparse matrix, this problem is somewhat more nontrivial. The best approach is probably to subtract the (max value * 2) from each nonzero element in each row. This seems ugly and hackish but I can't think of any other efficient way to solve it.
sub = max(0, max(myArray,[],2) * 2);
[i,j,v] = find(myArray);
v -= sub;
myArray = sparse(i,j,v);
[junk mi] = min(myArray,[],2);
EDIT: There are still precision issues if elements within a row have very different magnitudes. If this is the case, you can take negative inverses instead. In this way, you're not combining magnitudes from different elements in the matrix (or with any constant)
posOnly = ~any(myArray < 0, 2);
[i,j,v] = find(myArray);
inds = posOnly(i);
v(inds) = -1 ./ v(inds);
myArray = sparse(i,j,v);
[junk mi] = min(myArray,[],2);
(Note the use of ~any(myArray < 0) rather than all(myArray >= 0) because (myArray < 0) is at least as sparse as myArray whereas (myArray >= 0) is not sparse)
Using Dan's hint:
myArray(myArray==0)=Inf;
[m mi] = min(myArray, [], 2);
The values of mi will be the index of the minimum element in each row. Note the minimum is taken along the second dimension (per dspyz's suggestion).