how to save for loop data
Show older comments
I have a script that is calling from an excel file and interpolating the data in a for loop. The result is stored in the variable 'interamp' and i just need to know how to save the data with each iteration of the loop, before it is overwritten.
filename = 'sample file.xlsx';
data = xlsread(filename);
[rows, columns] = size(data);
dAmp = []; % holds amp for each trialFFTamp
dPhz = []; % holds phz for each trial
ctr = 1;
for col = 1 : 2 : columns
x = data(:, col);
y = data(:, col + 1);
hold on;[xData, yData] = prepareCurveData(x, y);
% Set up fittype and options.
ft = 'linearinterp';
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
InterAmp = fitresult(0:0.9765625:999);
end
Answers (1)
KSSV
on 19 Apr 2018
I = 1:2:columns ;
N = length(I);
iwant = cell(N,1) ;
for i = 1:N
col = I(I) ;
x = data(:, col);
y = data(:, col + 1);
hold on;
[xData, yData] = prepareCurveData(x, y);
% Set up fittype and options.
ft = 'linearinterp';
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
InterAmp = fitresult(0:0.9765625:999);
iwant{i}= InterAmp;
endCategories
Find more on Linear and Nonlinear Regression 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!