How to obtain a value from a program and replace in an equation?
Show older comments
Hello, everybody, i hope all of you have a wonderful day, my problem is this, i have this program, and from this program obtain this values of alpha from a series of data, this data obey this equation:


that are in function of the wind direction, but now, i want to obtain from this phormula the wind velocity but the alphas depend of the wind direction, so i have all, except the diferent type of alpha from every wind direction...
So if you can help me ... would be amazing. Thank you again.
Best!!
numData = xlsread('DireccionViento.xlsx');
alpha = numData(:,2);
DireccionViento = numData(:,1);
paso = 30;
kstd = 2;
direcs = (0:paso:360)';
s = length(direcs);
alpha_prom = nan(s-1, 1); %not a number
for k=1:(s-1)
MSKk = (DireccionViento>=direcs(k)) & (DireccionViento<=direcs(k+1));
alpha_k = alpha(MSKk);
% filtremos un poco antes del promedio
stdk = nanstd(alpha_k);
avek = nanmean(alpha_k);
MSKstd = (alpha_k > avek - kstd*stdk)&(alpha_k < avek + kstd*stdk); % kstd desvios estándar
alpha_msk = alpha_k(MSKstd);
meank = nanmean(alpha_msk);
alpha_prom(k) = meank;
% grafico
sk = length(alpha_k);
xk = (1:1:sk);
figure(k+1)
plot(xk, alpha_k, '.-b'); hold on; %valores de alpha
plot(xk(MSKstd), alpha_msk, '*r'); %gráficas con desviación estandár en rojo
plot(xk, meank+0*xk, '-g'); hold on; %promedio de alpha
end
x_direcs = direcs(1:s-1) + paso/2;
figure(1)
plot(x_direcs, alpha_prom, '*r') %grafica de alpha promedio con valores de grados
3 Comments
Image Analyst
on 9 May 2020
What are w1, w2, z1, and z2? I don't see them in your code. Can you use the same letters as the image so we know what is what?
Which variable in your code represents the velocity?
Sorry that I don't speak that language so I don't know what you're plotting. What do xk, alpha_k, alpha_msk, and meank represent? Is any of those velocity? Is xk time, distance, or something else? And in the third plot why are you multiplying the second term by 0? Because meank+0*xk is simply meank.
Can you attach the workbook so we can run your code?
Ana Soph
on 9 May 2020
Accepted Answer
More Answers (1)
Image Analyst
on 9 May 2020
Make 2 vectors then call polyfit().
direccion = 15 : 30 : 345;
alphas = [0.62, etc.
% Fit to a quadratic or whatever you want.
coefficients = polyfit(direccion, alphas, 2);
% Get fitted values
alphaFitted = polyval(coefficients, direccion);
plot(direccion, alphas, 'b.', 'LineWIdth', 2, 'MarkerSize', 20);
hold on;
plot(direccion, alphaFitted, 'r-', 'LineWIdth', 2);
grid on;
5 Comments
Image Analyst
on 9 May 2020
OK, I can help but you keep forgetting to attach 'DireccionViento.xlsx'. I have no idea what's in it. Does it just contain the table you showed a picture of? If so, why not attach the workbook and save me the trouble of having to type in hundreds of numbers?
Ana Soph
on 9 May 2020
Ana Soph
on 9 May 2020
Categories
Find more on Functions 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!
