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
Following advise from another post, I created a basic 3x3 averaging filter as follows:
blurP = zeros(512, 512);
for i = 1:510
for j = 1:510
sum = 0;
for k = i:i+2
for l = j:j+2
sum = sum+P(k,l);
end
end
blurP(i+1,j+1) = mean2(P(i:i+2,j:j+2));
end
end
imshow(P), figure, imshow(blurP, []);
I need to create a weighted filter with two options: One counts the center element (of the 3x3 grid) twice, thus giving me ten elements in total. The other has sixteen elements in total, with the center element counted four times and the adjacent ones counted twice—only the corner elements of the 3x3 grid are counted once.
The easiest option is to just use convolution (via the conv2 function). Then designing your kernels is a simple as writing out exactly what you described:
kernel1 = [1 1 1
1 2 1
1 1 1]/10;
blurP1 = conv2(P, kernel1, 'same');
and
kernel2 = [1 2 1
2 4 2
1 2 1]/16;
blurP2 = conv2(P, kernel2, 'same');
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have several struct of different dimensions in Matlab. Let us suppose that they were 5, the first is 1x100, the second 1x250, the third 1x200, the fourth 1x100, and the fifth 1x150. I want to assemble a new structure containing only the last element of the each previous structures, that is, I want to get a struct of the 1x5 form. How can I do this?
Create 5 row vectors, then make a row vector from the last elements like this:
>> a=[1:100];
>> b=[1:250];
>> c=[1:200];
>> d=[1:100];
>> e=[1:150];
>> the_lasts = [a(end), b(end), c(end), d(end), e(end)]
sthe_last =
100 250 200 100 150
>>
That also can be generalized into a function, using a file named:
ends_of.m :
function lasts = ends_of (varargin)
% prepare a result row vector with nargin dimention
lasts = zeros(1,nargin);
for i = 1:nargin
element = varargin(i); % get the arg
last = element{}(end); % find the last element
lasts(i) = last; % save it as index i
endfor
endfunction
Then it can be called like this :
>> ends_of ([1,2,3],[4,5,6],[1:44], [3:33], [1,2,3,2,1])
ans =
3 6 44 33 1
>>
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.
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 have a loop like this :
for i = 1:3
M = 1
for M = M:12
while (S(M) == i)
M = M+1
end
end
end
Now for the new incremented value of M in while loop the 'for' loop is not working for this new value.
Any solutions?
The code doesn't make any sense!
You should start to use different names for your parameters,
And note that:
for index = values
program statements
:
end
Avoid assigning a value to the index variable within the body of a loop. The for statement overrides any changes made to the index within the loop.
For the second loop for M = M : 12 is the same as for M = 1 : 12.
MATLAB takes the index values at their first definition, for example,
a = [1 2];
for i = a
disp(i);
a = [1 2 3];
end
You will see that i won't accept the value 3 because at the first use of for, i is set over [1 2].
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
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 have a vector [1 2 3 4 ... 100] and another vector storing the numbers I want to delete like [2 3 4]. After deleting, the numbers in original vector should be mapped to another order, for example, 1->1, 5->2, 6->3, etc. Is there any efficient way to do this? Thanks a lot!
I'd use setdiff:
% original vector
A = 1:100;
% elements to be removed
B = [2 3 4 18 21];
% new order (indices)
C = randperm(numel(A)-numel(B));
% Step 1) remove the elements
[D,I] = setdiff(A,B); % ordered
D = A(I); % restore original order
% Step 2) re-order the elements
D = D(C)
You can do:
original_vector = 1:100;
delete_vector = [2 3 4];
for ii = 1:length(delete_vector)
original_vector(original_vector==delete_vector(ii)) = [];
end