フィルターのクリア

plotting data from multiple sheets by ID and day

1 回表示 (過去 30 日間)
Sophia
Sophia 2023 年 2 月 20 日
コメント済み: Sophia 2023 年 2 月 20 日
Hi there,
I have data from multiple sheets of a workbook that I am looking to plot separately by ID (first column) and day (sheet name)
The data to plot from each sheet is column 6 (x) and column 5 (y)
The IDs run 1:48 - so 48 separate tiled plots, and within each plot is (up) to 8 lines (days or sheets - which would be the legend)
I am wondering whether this is possible for separate sheets
So far i have used splitapply to group the data by ID but this still plots all the IDs on one graph - not sure how I can separate this and also include the other sheets
B = findgroups(RLCAD(:,1));
dataByID = splitapply( @(varargin) varargin, RLCAD, B);
[nID, ~]=size(dataByID);
figure;
hold on;
for i=1:1:nID
plot(dataByID{i,6},dataByID{i,14});
end

採用された回答

KSSV
KSSV 2023 年 2 月 20 日
編集済み: KSSV 2023 年 2 月 20 日
fname = 'https://in.mathworks.com/matlabcentral/answers/uploaded_files/1300500/RLC_AD.xlsx' ;
sheets = sheetnames(fname) ;
h = cell(8,48) ;
figure
for i = 1:length(sheets)
T = readtable(fname,'Sheet',sheets(i)) ;
id = T.(1) ;
F = T.(6) ; % This is x-axes data
Yield = T.(4) ; % This is y-axes data
for j = 1:48
fprintf('%s sheet of %d id\n',sheets(i),j) ;
hold on
h{i,j} = subplot(8,6,j) ;
plot(h{i,j},F(id==j),Yield(id==j))
title(sprintf('id=%d',j))
drawnow
if i == length(sheets)
legend(sheets)
end
end
end
  3 件のコメント
KSSV
KSSV 2023 年 2 月 20 日
Yes you can do that...edited the answer.
Sophia
Sophia 2023 年 2 月 20 日
Perfect, thank-you

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

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 20 日
Here is the complete solution code:
FName = 'RLC_AD.xlsx';
for jj=1:numel(sheetnames(FName))
RLCAD = readmatrix(FName, 'Sheet', num2str(jj));
B = findgroups(RLCAD(:,1));
dataByID = splitapply( @(varargin) varargin, RLCAD, B);
[nID, ~]=size(dataByID);
figure(jj);
for i=1:nID
x = dataByID{i,1}(:,6);
y = dataByID{i,1}(:,5);
plot(x,y); hold all
end
title(['Sheet # ' num2str(jj)])
hold off
end
  1 件のコメント
Sophia
Sophia 2023 年 2 月 20 日
Hi, thanks for this but I am looking to split the data by ID rather than by sheet
I sampled 48 species and each sheet is a time point so would like to see 48 plots each with a legend - so one plot may have data from each sheet

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

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by