Plotting multiple graphs from multiple ranges in excel

15 views (last 30 days)
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!

Answers (1)

Chad Greene
Chad Greene on 30 Apr 2021
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 Comments
Oliver Hancock
Oliver Hancock on 30 Apr 2021
Thanks, this seems do the trick but it plots all the points in the same figure. Is there a way of getting the individual plots or is it just a matter of manually increasing k between 0 and 47 and then saving them induvidually?
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 i.e 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("AllAMDataCollated.xlsx","Sheet2",time);
figure1 = xlsread("AllAMDataCollated.xlsx","Sheet2");
x = figure1(:,1);
y = figure1(:,2);
hold on
for k=0:47
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),'.')
title(["AM Data Points"])
xlabel("Xpixels")
ylabel("Ypixels")
grid
end
Chad Greene
Chad Greene on 30 Apr 2021
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

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!