How do I succefully do a Summation in Maltab
1 view (last 30 days)
Show older comments
Hello.
I am trying to create a result, which would give me and vector A_i, with N values each representing an activation level.
I have done a nested for loop, because i = 1....,N and F(-1) = F(1) = -0.1 and F(0) =1
Where I = [1 1 1 1 1 0 0 0 0 0] and N = 10;
And another case Where I = [0 0 0 0 0 1 2 3 4 5 6 7 8 9 9 9 9]
However, I have yet to succed. Because I run into a problem with the implementation of F(j) and (i+j).
If anybody has some ideas, it would be to great help.
Kind Regards,
0 Comments
Answers (2)
William Rose
on 4 Mar 2021
I see that you are computing a 3-point weighted moving average, where the weighting factors are (-.1,+1,-.1). This is an example of a convolution, and Matlab has a conv() function for this. The output from conv() includes the edges, where the two vectors overlap by just 1 point. From your problem statement, I understand that you only want the ouput when F is centered over each point in I(), so you will have to remove the first and last points from the vector output of conv(). If your F vector were 5 points wide, you would have to remove the first two points and the last two points from the output of conv().
%MabelCode.m WCR20210304
F=[-.1 1 -.1];
I1 = [1 1 1 1 1 0 0 0 0 0];
I2 = [0 0 0 0 0 1 2 3 4 5 6 7 8 9 9 9 9];
A1=conv(I1,F); %do the convolution
A1=A1(2:end-1); %remove first and last point
A2=conv(I2,F); %do the convolution
A2=A2(2:end-1); %remove first and last point
%plot results
subplot(2,1,1);
plot(1:10,I1,'rx',1:10,A1,'bo');
legend('I1','A1');
subplot(2,1,2);
plot(1:17,I2,'rx',1:17,A2,'bo');
legend('I2','A2');
William Rose
on 4 Mar 2021
To get output from more cells, just extend the input vector A with zeros on either side. The number of outputs, with the script I wrote, will equal the number of inputs. I see from the weighting that this is a center-on, off-surround type input, as is true for some retinal ganglion cells.
The weighting factors of A=[-.1,+1.0,-.1] respond mainly to the center level, with a modest amount of edge detection. If you make the negative values more negative, then your cell becomes more of an edge detector. You can examine this by stimulating your cell array with black (0) and white (1) bars, or with ramps (triangle waves). A pure edge detector cell is A2=[-.5,+1,-.5]. By "pure" I mean that its response is zero to all-white stimulus and to all-black stimulus. It repsonds most strongly where the second derivative of the input is high, like at edges and at the corners of a triangular input.
4 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!