How would I create a loop where I exclude values greater than a certain value and re-run it repeatedly?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Here is the full text of the part of the problem I am working on:
"Calculate the error between the measured function values (ydata) and the function evaluations using your A and B parameters, this should be a vector of 2346 errors. Eliminate all points that have an individual error of more than twice the average error, and refit your A and B parameters without these points. Repeat this process until all points used for determining A and B have an error less than twice the average error. Plot the original data, with the used points in a different color than the discarded points, as well as your final function evaluation on the same axis."
So far here is my code (this includes steps not pictured):
close;
clear all;
load ("ExamData.mat");
x1 = xdata';
y1 = ydata';
f = fittype('(a*sin(0.7*log(x)))+(b*cos((-0.1)*x))');
[fitted_curve,gof] = fit(x1,y1,f);
MyCoeffs = coeffvalues(fitted_curve);
coeff_1 = MyCoeffs(1);
coeff_2 = MyCoeffs(2);
problem1b = fitted_curve(x1)
scatter(x1,y1)
hold on
plot(x1,problem1b)
hold off
Percent_error = 100*(problem1b-y1)./(y1)
Calc_error = abs(Percent_error)
Average_error = mean(Calc_error)
doubleerrror = Average_error.*2
I don't really know where to go from here. I want to know how I could separate values from the vector and then re-run the equation with new coefficients, but I have not the slightest idea how to actually do that.
I'm not asking you to solve it for me. I just want to get a general idea of HOW to do it, at least with a list of commands I would need to use.
11 Kommentare
Walter Roberson
am 7 Apr. 2020
if find(var1<var2) = false
Bad syntax: MATLAB uses == for comparisons.
What you want to know is whether ind is empty. The best way to test that is with isempty()
Antworten (1)
Walter Roberson
am 7 Apr. 2020
how to set the start point for the fit function
3 Kommentare
Walter Roberson
am 7 Apr. 2020
You want ind to be the list of locations where the mean is exceeded .
Siehe auch
Kategorien
Mehr zu Particle & Nuclear Physics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!