필터 지우기
필터 지우기

take sum log of selected elements of matrix

조회 수: 1 (최근 30일)
Jay Hanuman
Jay Hanuman 2016년 11월 15일
편집: Jay Hanuman 2016년 11월 15일
I have 1000 length sequence x=[1 3 5 5 4 1 2 2 1 4 5 3 3 1 2 5 4......] and p matrix below.
1 2 3 4 5
1 0.0865 0.5096 0.1538 0.1346 0.1154
2 0.1070 0.4156 0.1317 0.2263 0.1193
3 0.0789 0.2105 0.0965 0.3070 0.3070
4 0.1194 0.0806 0.1290 0.3387 0.3323
5 0.0965 0.1754 0.0658 0.4474 0.2149
for window size 6 I am selecting 6 data points i.e. 1 3 5 5 4 1 so I want to do
log(P(1,3))+log(p(3,5))+log(p(5,5))+log(p(5,4))+log(p(4,1)).
now I am sliding window by 1 to next i.e. adding next element and skipping previous element of sequence i.e. 3 5 5 4 1 2 & want to do same thing i.e.
log(P(3,5)+log(p(5,5))+log(p(5,4))+log(p(4,1))+log(p(1,2))
and this is upto last of sequence i.e. for 1000 length sequence this operation has 995 times. how to do this.
  댓글 수: 1
John D'Errico
John D'Errico 2016년 11월 15일
Is the window size of varying length? Or is it fixed at 6 elements?
You state that for a vector if indices of length 1000, there will be 1995 such operations. Sorry, but as you have explained it, it looks like only 995 operations, NOT 1995.
So you need to be more clear when you ask a question. Otherwise, we are forced to guess.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2016년 11월 15일
I think since the elements of x could have virtually any index values, you'll have to do this in a for loop. And I assume you know that P and p are different variables since MATLAB is case sensitive. So, something like
x = [1 3 5 5 4 1 2 2 1 4 5 3 3 1 2 5 4......]
windowLength = 6;
for windowStart = 1 : length(x)-windowLength+1
out(windowStart) = log(P(1,3)); % Initialize with the Capital P array element.
for k = 1 : windowLength - 1
row = x(k);
col = x(k+1);
out(windowStart) = out(windowStart) + log(p(row, col));
end
end
  댓글 수: 1
Torsten
Torsten 2016년 11월 15일
I think the OP meant something like
x = [1 3 5 5 4 1 2 2 1 4 5 3 3 1 2 5 4......]
windowLength = 6;
for windowStart = 1 : length(x) - windowLength + 1
out(windowStart) = 0.0;
for k = windowStart : windowStart + windowLength - 2
row = x(k);
col = x(k+1);
out(windowStart) = out(windowStart) + log(p(row, col));
end
end
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by