How can I change input of function from file to cell array?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have this function dfaedit_2('filename.csv',0,0,0) and it only takes files as input. I have a cell array with a size of 19x21.
I would like to change the input into a cell array.
When I run it however I get an error:
Error using cumsum
Invalid data type. First input argument must be numeric or logical.
Error in dfaedit (line 44)
Sum = cumsum(x);
Help is much appreciated!
0 commentaires
Réponse acceptée
David Hill
le 26 Jan 2022
Modifié(e) : David Hill
le 26 Jan 2022
Either delete or comment out lines below and change input to data. Verify cell2mat(of your cell array) gives what is expected. Or provide a sample of your input cell array and previous data file.
data=yourCellarray;
H=dfaedit(data,1,1,1);%call function
function [H]=dfaedit(data,plot_flag, outfile_flag, out_command_flag)
format short g
%x = file_name;
%fid = fopen(file_name);
%data = textscan(fid,'%f');
%fid = fclose(fid);
x = cell2mat(data);
7 commentaires
David Hill
le 27 Jan 2022
function [H]=dfaedit(data)
format short g
for k=1:numel(data)
y = data{k};
h=[];
for kk=1:size(y,2)
x=y(:,kk);
numberpoints = length(x);
MinBox = 4; % minbox #of points in a box
MaxBox = .25*numberpoints; % maxbox set 1/4 the data length
BoxSizeDensity = 4;
LogScaleFactor = power(2.0, 1.0/BoxSizeDensity);
index = 1:numberpoints;
index = reshape(index, length(index), 1); %change row to column vector
% Preliminary calculations
Sum = cumsum(x);
SumOfSumsSquared = cumsum(Sum.*Sum);
SumOfSums = cumsum(Sum);
SSc = cumsum(index.*Sum);
% now find best fit lines and find fluctuation about the line
% loop for each box size, from MinBox to MaxBox
iteration = 1;
BoxSize = MinBox;
TempBoxSize = MinBox;
while BoxSize <= MaxBox
s = 0.0;
r1 = 1./(BoxSize + 1.0);
Det = 12.0*r1*r1*r1/(1.0 - r1*r1);
vv = BoxSize*(2.0*BoxSize + 1.0)/6.0;
for j = 2:numberpoints - BoxSize
dhh = SumOfSumsSquared(j + BoxSize) - SumOfSumsSquared(j-1);
dhu = SumOfSums(j + BoxSize) - SumOfSums(j-1);
dhv = SSc(j + BoxSize) - SSc(j-1) - dhu*j;
s = s + dhh - (dhv*dhv +dhu*dhu*vv - dhv*dhu*BoxSize)*Det;
j = j + 1;
end
den = (numberpoints - BoxSize)*(BoxSize + 1.0);
Fluctuation = sqrt(s/den);
log_points_in_box(iteration,1) = log10(BoxSize);
log_Q(iteration,1) = log10(Fluctuation);
show_results(iteration,:) = [ iteration BoxSize Fluctuation log_points_in_box(iteration,1) log_Q(iteration,1) ];
iteration = iteration + 1;
% update the box size
TempBoxSize = TempBoxSize*LogScaleFactor;
while round(TempBoxSize) < BoxSize + 1.0
TempBoxSize = TempBoxSize*LogScaleFactor;
end
BoxSize = round(TempBoxSize);
end
% got all boxes; now calculate H via trendline
r_trend = corrcoef(log_points_in_box, log_Q);
coefs = polyfit(log_points_in_box, log_Q,1);
r_line = polyval(coefs,log_points_in_box);
% calculate dimension and Hurst
h(kk) = coefs(1);
D = 2-h(kk);
end
H{k}=h;
end
end
Plus de réponses (1)
lil brain
le 27 Jan 2022
2 commentaires
David Hill
le 27 Jan 2022
function [H]=dfaedit(data)
format short g
H=cell(size(data));%just add this line at the beginning
Voir également
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!