Plotting Data from a For Loop and If statement
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
dpb
el 8 de Ag. de 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... :)
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!