Create a loop that add data from different datasets into a plot
이전 댓글 표시
Hello,
I am trying to create a specific a loop that would allow me to add new data in a plot.
Let me explain, I have several datasets (12) with 3 ≠ sheets everytime from which I am calculating mean between rows, diff between rows and mean of differences.
I'd like to do that for all my data sets and then plot all the mean and diff on the same plot, without having to create a new dataset and save means and diffs independantly.
My aim is to create a bland-altman plot of every datasets based on Pre, BH and Post using different symbols between trials and colors between Pre,BH and Post.
Here is the row code doing so for one dataset:
for n=4 %first data set
file=[datapath,d(n).name];
Pre = readtable(file,'Sheet',"Pre"); %sheet 1 of dataset1
Pre=table2array(Pre(:,["Var3","Var8"]));
BH = readtable(file,'Sheet',"BH"); %sheet 2 of dataset1
BH=table2array(BH(:,["Var3","Var8"]));
Post = readtable(file,'Sheet',"Post"); %sheet 3 of dataset1
Post=table2array(Post(:,["Var3","Var8"]));
meanPre=mean(Pre,2);
meanBH=mean(BH,2);
meanPost=mean(Post,2);
diffPre=diff(Pre,1,2);
diffBH=diff(BH,1,2);
diffPost=diff(Post,1,2);
meandiffPre=mean(diffPre);
meandiffBH=mean(diffBH);
meandiffPost=mean(diffPost);
scatter(meanPre,diffPre,'Marker','x','MarkerEdgeColor','r')
hold on
scatter(meanBH,diffBH,'Marker','x','MarkerEdgeColor','b')
scatter(meanPost,diffPost,'Marker','x','MarkerEdgeColor','m')
hold off
end
Thanks,
Marine
댓글 수: 2
Image Analyst
2022년 11월 18일
It would be easier if you'd attach at least two files. Make it easy for us to help you, not hard.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Marpe
2022년 11월 18일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
