MATLAB Answers

Plotting multiple graphs from multiple ranges in excel

8 次查看(过去 30 天)
Oliver Hancock
Oliver Hancock2021-4-30
评论: Chad Greene ,2021-4-30
I'm very very new to matlab and I need to produce a graph for each range of data for 49 specific timestamps
range = "C2:D41"; %increments by 40 each time ie next range is C42:D81 ect for 49 times
time = "H2"; %also increments by 40 each for each timestamp ie next timestamp text is at H42
%below needs to be in a loop that produces a new figure for each time if that's possible
[~,txtData] = xlsread("AllDataCollated.xlsx","Sheet2",time);
figure1 = xlsread("AllDataCollated.xlsx","Sheet2",range);
x = figure1(:,1);
y = figure1(:,2);
plot(x,y,'.')
title([txtData,"(HHMMSS)"])
xlabel("Xpixels")
ylabel("Ypixels")
grid
This creates the figure below, of which I need 48 more for the other times
any help would be greatly appreciated!

回答(1 个)

Chad Greene
Chad Greene 2021-4-30
The easiest way is probably to read the full range of data all at once, then loop through the different ranges you want to plot. So after reading the excel data,
x = figure1(:,1);
y = figure1(:,2);
hold on
for k=0:48
ind = (k*40+1):40*(k+1); % indices of data to plot. When k=0 ind equals 1 to 40. When k=1 ind equals 41 to 80
plot(x(ind),y(ind),'.')
end
  2 个评论
Chad Greene
Chad Greene 2021-4-30
If you want 49 subplots on the same figure, you could do it like this:
figure
for k = 0:48
subplot(7,7,k+1)
plot(rand(10,1),rand(10,1),'o')
axis tight
box off
title(['number ',num2str(k+1)])
end

请先登录,再进行评论。

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by