How can I store the output value from each for loop?
Show older comments
The for loop in the code below reads data from a number of .csv files (approx 250). Everything is working as it ought to be but I cannot store the 'Error' value I have created at the end of the loop. I've looked into examples online and often the use of Error(i) seems to be the solution; however, this doesn't work (I know I don't have an i in my code, instead I use file = files'). Is it something to do with the file = files' statement at the beginning of the loop? Thanks!
clc;
close all;
files = dir('*.csv');
Input_grad = 45;
Disp_lower = 1;
Disp_upper = 1.6;
for file = files'
filename = fopen(file.name);
A = textscan(filename,'%q %q %q','HeaderLines',3,'Delimiter',',')
Time = A{1,1};
Timex = cellfun(@str2num,Time);
Force = A{1,2};
Forcex = cellfun(@str2num,Force);
Disp = A{1,3};
Dispx = cellfun(@str2num,Disp);
Range = (Dispx > Disp_lower & Dispx < Disp_upper );
Position = find(Range==1);
Disp_range = Dispx(Position,:);
Force_range = Forcex(Position,:);
Grad = (Force_range(end))-(Force_range(1))/(Disp_range(end))-(Disp_range(1));
Error = abs(Input_grad - Grad)
fclose(filename);
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!