create a "moving window" plot

조회 수: 10 (최근 30일)
Emily Platt
Emily Platt 2021년 6월 20일
댓글: Emily Platt 2021년 6월 21일
Hello, I have a cell array that i want to plot (all numeric values) called RR. the data was collected over time so values lower down would be later in time. i want to plot multiple plots on seperate figures in a moving window apporach.
I want to plot the first 257 points, and then the next 257 on a seperate plot etc and then the final plot which will be smaller than the rest
i know to use the first one I'd type:
plot(RR(1:257))
and then i'm assuming i should use a for loop but im struggling to incoporate it
Thank you in advance

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 20일
Assuming numeric RR
for base = 1 : 257 : length(RR)
idx = base : min(length(RR), base+256);
figure
plot(idx, RR(idx));
end
  댓글 수: 1
Emily Platt
Emily Platt 2021년 6월 21일
Thank you very much!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 6월 20일
Unfortunately you forgot to attach your cell array. If it's bigger than 5 MB, crop it down. Then use the paperclip icon so we can try things.
How many cells are in the cell array? Are the contents of each of the cells in the cell array the same (like a 1-D 257 element vector) or does each array have a different size? What is the size of the contents of the array in each cell? Why are you even using cell arrays instead of a normal 3 or 4-D double array (why complicate things)?
If ca is your cell array
for k = 1 : length(ca)
thisVector = ca{k}; % Assume each cell has a long vector in it.
indexes = unique([1 : 257 : length(thisVector), length(thisVector)]);
for k2 = 1 : length(indexes) - 1
index1 = indexes(k2);
index2 = indexes(k2 + 1) - 1;
plot(thisVector(index1:index2), '-', 'LineWidth', 2)
hold on;
end
end
grid on;
hold off;
  댓글 수: 1
Emily Platt
Emily Platt 2021년 6월 20일
hello, thank you for your help, there are 1402 cells in total. ive now moved the data to a 1402x1 double to make it easier since it should just be a simple plot from here?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by