Plotting Data from a For Loop and If statement

8 visualizzazioni (ultimi 30 giorni)
Natha Davis
Natha Davis il 6 Ago 2020
Commentato: Natha Davis il 10 Ago 2020
So I have a complicated data structure. ParentFolder contains 33 "cases" inside each case there ranges from 1-3 separate DTI "scans". I want to go into those scans subfolders and get several specific files and then plot them in a variety of ways and I am struggling with how to combine the "if" statements and the for loop to be able to load the data in a way thats graphable. Right now everything is in character arrays, but maybe a struct is better? Here is my for loop I have so far:
cases = dir([casedir '*Casenames*']); %this displays the 33 cases inside the parent folder
for cas= 1:length(cases);
casefold=([casedir cases(cas).name filesep]);
pexfold1= ([casefold '*V01*']); %the different conditions
pexfold2= ([casefold '*V02*']);
postexfold=([casefold '*V03*']);
if exist ('pexfold1');
dtipex1fa=([pexfold1 filesep 'dti' filesep 'fastats.txt' filesep]);
dtipex1adc=([pexfold1 filesep 'dti' filesep 'adcstats.txt' filesep]);
T1FA= ([pexfold1 filesep 'dti' filesep 'Anatomy 3.fa.txt' filesep]);
T1ADC=([pexfold1 filesep 'dti' filesep 'Anaomty 3.adc.txt' filesep]);
else
dtipex1fa=[];
dtipex1adc=[];
T1FA=[];
T1ADC=[];
end
if exist ('pexfold2');
dtipex2fa=([pexfold2 filesep 'dti' filesep 'fastats.txt' filesep]);
dtipex2adc=([pexfold2 filesep 'dti' filesep 'adcstats.txt' filesep]);
T2FA= ([pexfold2 filesep 'dti' filesep 'Anatomy 3.fa.txt' filesep]);
T2ADC=([pexfold2 filesep 'dti' filesep 'Anatomy 3.adc.txt' filesep]);
else
dtipex2fa=[];
dtipex2adc=[];
T2FA=[];
T2ADC=[];
end
if exist ('postexfold');
dtipostfa= ([postexfold filesep 'dti' filesep 'fastats.txt']);
dtipostadc= ([postexfold filesep 'dti' filesep 'adcstats.txt']);
TPostFA= ([postexfold filesep 'dti' filesep 'Anatomy 3.fa.txt']);
TPostADC=([postexfold filesep 'dti' filesep 'Anatomy 3.adc.txt']);
else
dtipostfa=[];
dtipostadc=[];
TPostFa=[];
TPostADC=[];
end
end %then ideally I would graph pexfold1 vs pexfold2 vs postexfold and perform statistical tests
Anatomies = {'Anatomy 1';'Anatomy 2';'Anatomy 3'};
Times = {'Condition 1'; 'Condition 2'; 'Condition 3'};
What happens right now it says there is always a pexfold1,2 and postexfold no matter what, but those are the folders that vary in existance between cases. I am trying to graph the fa values of each condition against each other, adc against each other and the stats against each other. Inside each of the "fastats" and "adcstats" txt files there are 3 different anatomical landmarks which have mean DTI values to graph. The Anatomy 3 txt files only have 1 anatomical landmark. I am just tripped up on how to progress through this if the file in question doesn't exist and how to get to the data when its stuck in a character array. Thank you for reading my long post and for your help!
  7 Commenti
dpb
dpb il 8 Ago 2020
Hmmm....I'm sure there's a way to automate the generation other than physically writing each manually. But, I don't have the stamina to continue tonight to try to figure out just what the result is that needs discerning clearly enough in my mind to actually write code.
I do think it would help immeasurably if you could just list the directory structure of the files so can actually see it--not the data in the files but the file storage structure/naming conventions. That would also illustrate by example the disconnect you're trying to code around.
Just otomh, it seem like simply traversing the directory tree for the directory entries and processing them would be fairly straightahead route where one can pass the wildcard to the OS for matching the directories. But, seeing it all laid out in front of us would help immeasurably. Remember you know all this and it's clear to you; we can't see your terminal so know only what is written on the message screen here.
Once we can work through that part of the problem, it will probably be clear where the data are that are needed and how to consolidate them as needed--quite likely a cell array might be an intermediary that then gets manipulated to put things together as needed to plot the necessary variables against the desired...
But, I'm wore out tonight, sorry... :)
Natha Davis
Natha Davis il 10 Ago 2020
No problem! I apologize not being able to show as much information as you need, I know its frustrating and belive me I am frustrated as well. I can write out the general file structure here and see if that helps:
My Downloads Folder
Folder with 30 Cases (Parent Folder)
Each of those cases has 1 to 3 different Versions (V01, V02, V03). These versions correspond to different time points in the same case. Think of 1 as before, 2 as during and 3 as after.
Inside each of those version folders is a folder called "dti"
Inside each "dti" are 2-3 "txt" files corresponding to different ROIs highlighting certain anatomical regions
Each txt file looks like the attached picture
Out of the values in the file I want to graph and test the means from these different versions (V01, 02, 03) on the same graph. So each of the anatomical region graphs would have data from each of the time points. The graph that corresponds to one anatomical area would show "before, during, after". Then a different graph for a different ROI shows "before, during, after" etc.
So what I ended up doing in my last comment was just point MATLAB to ALL of the cases and versions and then group them by case. "Case 1 V01, group.1" "Case 1 V02, group.2" "Case 2 V01, group.2" "Case 2 V02, group.2" etc. But I feel like there is definitely a more efficient way and dynamic way so that when we are able to get more timepoints for some of these that only have 1-2 versions we can easily detect them instead of having to write out every single individual case. I hope that helps! I apologize for the secrecy, but thank you so much for your continued help!

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by