MATLAB: Streamlined naming outputs from one location

designating ouputs

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.
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

Best Answer

  • TrialNumber = 4;
    CT_pattern = sprintf('CTraj%02d.*', TrialNumber);
    CT_dinfo = dir(CT_pattern);
    CT_filenames = {}:
    FD_pattern = sprintf('FDTraj%02d.*', TrialNumber);
    FD_dinfo = dir(FD_pattern);
    FD_filenames = {};
    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.