Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

matlab - Octave GNU - Searching multiple folders and their files at different points in program within cd

I have been struggling with this issue for a few days now and I decided to see if someone more experienced could help me out. I am currently developing a data analysis program designed to load and manipulate various data files. I have 3 folders each with 1 type of 30 files, represented by trial_001...trial_30, trial_n3d_001...trial_n3d_030, and trial_com_n3d_001...trial_com_n3d_030. These files are similar but possess differences in terms of types of data as well as total number of data columns and rows. Currently, the portion of my code for loading the data looks like this:

cd = dir('*.csv');
n = length(cd); 
data = cell(1,n); 
for files = 1 : n %For the first file up to the total amount of files
  data(files) = csvread(cd(files).name); %Read in csv files
endfor
data = cell2mat(data); %Create single large dataset

This is successful in looping through my current working directory and obtaining all files and then inputting them into a single large dataset which is intended. I am able to perform all of my calculations. The problem is that I cannot seem to specify subfolders with this method, rather it only works if I manually load directly from one of the folders. I need the program to work on multiple computers and I would prefer if I did not have to set the loadpath within the code each time and simply use the path I choose manually when starting octave in the file browser and instead specify generic folder names.

So my question is how do I do exactly what I am doing currently but from the previous folder containing all three folders and their respective files, and search each of these folders at different points in my code? I want my data variable to act as a working dataset, and load in each of the three types of files at different times and perform different calculations (effectively resetting that data variable after loading all files from each folder and performing calculations). I have tried addpath, genpath, etc. as well as manipulating the common directory and creating variables representing each folders location but I cannot seem to get it to work. Any suggestions?

question from:https://stackoverflow.com/questions/65622895/octave-gnu-searching-multiple-folders-and-their-files-at-different-points-in-p

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...