Streamlined naming outputs from one location

조회 수: 1 (최근 30일)
Robert J Hanna
Robert J Hanna 2020년 10월 21일
답변: Walter Roberson 2020년 10월 21일
I am currently trying to work on 3D modeling of hummingbird flight trajectories. I work with many data sets that are similarly named but with distinctions;
e.g. CTraj04.3_130516 = Chase Trajectory, trial 4, update 3, May13 '16
e.g. FDTraj01.2_130516 = Freely Departing Trajectory, trial 1, update 2, May13 '16
Within the code, each data set is ran independently. This is dependent on the working folder and the specific data set chosen (i.e me typing in the trial number info in these different locations before running). What I wanted to ask is if there is an easy way to designate the trial number at one location and have it applied to these other spots.
%IMPORT FILES
data = importdata('CTraj04.3_130516-xyzpts.csv');
weights = importdata('CTraj04.3_130516-spline-weights.csv');
tol = importdata('CTraj04.3_130516-spline-error-tolerances.csv');
...
writetable([AVS, AAS, CVS, CAS], 'Varience04.3_130516.csv');
the writetable() is much further down the code and it would save some time to somehow designate the trial numbers at one point to then be assigned to these different locations.
Not sure if this explains it well but I'd appreciate any help

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 21일
TrialNumber = 4;
CT_pattern = sprintf('CTraj%02d.*', TrialNumber);
CT_dinfo = dir(CT_pattern);
CT_filenames = {CT_dinfo.name}:
FD_pattern = sprintf('FDTraj%02d.*', TrialNumber);
FD_dinfo = dir(FD_pattern);
FD_filenames = {FD_dinfo.name};
Update_number = 3;
TrialDate = 130516;
CT_basename = sprintf('CTraj%02d.%d_%06d-', TrialNumber, Update_number, TrialDate);
xyzfile = [CT_basename 'xyzpts.csv'];
weightfile = [CT_basename 'spline_weights.csv'];
etfile = [CT_basename 'spline-error-tolerances.csv'];
data = importdata(xyzfile);
weights = importdata(weightfile);
tol = importdata(etfile);
Note: I do not recommend using importdata. I find that it is too random as to what fundamental data structures it returns. For example a file that is pure numbers is returned as a numeric array, but as soon as you add one line of comments it gets returned as a struct, but if there appears to be a header for each column then it gets returned as a table object. Furthermore when it returns a struct, the field names it returns can change depending on what it thinks it understands of the file. Every time you use importdata() you need to test and decode the return values.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by