How do I succefully do a Summation in Maltab

1 回表示 (過去 30 日間)
Mabel
Mabel 2021 年 3 月 4 日
コメント済み: William Rose 2021 年 3 月 10 日
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,

回答 (2 件)

William Rose
William Rose 2021 年 3 月 4 日
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');
  2 件のコメント
Mabel
Mabel 2021 年 3 月 4 日
Thank you so much!
Actually your explanation has not only opened my for the coding, but understanding the the overall theme much better. I have been looking at it from a wrong perspective. Thank you.
However, I have trouble seeing how N is to be implemented or how it is considered when using convolution.
For example in the case for the second case (A2 and I2), one wishes to get the activation level (A2) for 18 cells when stimulated by the input as shown above. So i = 1....,18. How is this inplemented?
Thank you again! Just making sure i fully understand!
darova
darova 2021 年 3 月 5 日

サインインしてコメントする。


William Rose
William Rose 2021 年 3 月 4 日
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 件のコメント
Mabel
Mabel 2021 年 3 月 10 日
Ohh. I am about to try that! Thank you so much. You have really helped me alot!:)
William Rose
William Rose 2021 年 3 月 10 日
You're welcome @Mabel

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by