Read multiple files and store fitting parameters & graphs
Mostra commenti meno recenti
I have a function that reads from an input file (floating point numbers, only) columns (A, B, C, D, E, F, G, H, I) perform some mathematical operations and plot some fittings.
Since I have multiple input files named as: res1, res8, ..., resn, attention not in sequencial order (meaning not having res2, for example) how should I do for my script read all those input files and for each run/analysis create an output file results1, results8 ... etc, with fitting results and plots?
Any help would be much appreciated.
4 Commenti
Stephen23
il 12 Feb 2019
Angelo Figueiredo
il 12 Feb 2019
Bob Thompson
il 12 Feb 2019
You're only getting one set of outputs because you're only looking at mydata{k}, where k is numfiles (the last one). If you want to perform the operation for all of the files, move them all inside the loop, including the output.
Angelo Figueiredo
il 12 Feb 2019
Risposte (2)
Bob Thompson
il 12 Feb 2019
0 voti
function [results] = test(A,B,C,D,E,F,G,H,time)
numfiles = 2;
mydata = cell(1, numfiles);
for k = 1:numfiles
myfilename = sprintf('Res%d.txt', k);
mydata{k} = importdata(myfilename);
A = mydata{k}(:,1);
B = mydata{k}(:,2);
C = mydata{k}(:,3);
D = mydata{k}(:,4);
E = mydata{k}(:,5);
F = mydata{k}(:,6);
G = mydata{k}(:,7);
H = mydata{k}(:,8);
time = mydata{k}(:,9);
ABsub = E - E(1);
BAsub = G - G(1);
ref = A(1) + C(1);
AA = A/ref;
BB = B/ref;
AB = ABsub/ref;
BA = BAsub/ref;
% Insert new database creation here
% Insert output command here
end
Angelo Figueiredo
il 13 Feb 2019
8 Commenti
Bob Thompson
il 13 Feb 2019
Move everything except for the zex function inside the loop.
Angelo Figueiredo
il 13 Feb 2019
Bob Thompson
il 13 Feb 2019
You are receiving that error because your structure field is named the same as your index (k). I would recommend changing the name of the structure field, since it should be a unique variable name anyway.
Angelo Figueiredo
il 13 Feb 2019
Bob Thompson
il 13 Feb 2019
To the best of my knowledge, almost any time a variable is specified using dot convention it is considered a structure by default. You are defining 'default.k' as equal to a value. In this command 'default' is the structure name, and 'k' is the name of the field in the structure. You cannot do this within your for loop because you have 'k' assigned as the index variable of the loop. This can be simply solved by changing default.k into something like default.kVal, or whatever you would like to name it as. (Subsequent callings of default.k will also need to be changed.)
Angelo Figueiredo
il 13 Feb 2019
Bob Thompson
il 13 Feb 2019
Mmm, I forgot this part. Put brackets around your new structure field definitions.
[default.ex] = 3.2;
[default.pA] = ...
Angelo Figueiredo
il 16 Feb 2019
Categorie
Scopri di più su Software Development Tools in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!