Info

This question is closed. Reopen it to edit or answer.

why am I having problems with a string and vector and how to use a *?

2 views (last 30 days)
hello!
i am trying to load a bunch of .txt files that are in different subject folders, but when i try to run the script with more than one subject, i get errors saying 'Must be a string scalar or character vector'.
The data is all in folders:
/Users/ll/Documents/data_analysis/HCP/seventy/HCA*/ts/cortex.txt
The only changing aspect is the subject number, and I can't figure out how to make it a variable. I have a ton of subjects to do analysis, so it would be great if i didn't indiviudally have to put the subject name in. Does anyone have any ideas? Thanks so so much.
My code:
subj = {'HCA1','HCA2'}; %HCPsubj list
for a = 1:numel(subj)
(subj{a})
end
D = ['/Users/ll/Documents/data_analysis/HCP/seventy/', subj];
for k = 1:2
name = sprintf('ts',k); % HCA1, HCA2, etc.
l = load(fullfile(D,name,'lcortex_run01regPA.txt'));
v = load(fullfile(D,name,'ventricle_run01regPA.txt'));
s = load(fullfile(D,name,'spinal_run01regPA.txt'));

Answers (1)

Walter Roberson
Walter Roberson on 29 Dec 2019
subj = {'HCA1','HCA2'}; %HCPsubj list
D = '/Users/ll/Documents/data_analysis/HCP/seventy/';
for k = 1:length(subj)
name = subj{k};
l = load(fullfile(D,name,'lcortex_run01regPA.txt'));
v = load(fullfile(D,name,'ventricle_run01regPA.txt'));
s = load(fullfile(D,name,'spinal_run01regPA.txt'));
...
end

This question is closed.

Community Treasure Hunt

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

Start Hunting!