How to obtain a value from a program and replace in an equation?

1 view (last 30 days)
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
Ana Soph
Ana Soph on 9 May 2020
Edited: Ana Soph on 9 May 2020
in this file i have in the first column the wind direction and in the second the wind velocity, this wind velocity is the wind velocity that i want to replace in the phormula for obtain the other wind velocity (18 meters)...
Best!

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 10 May 2020
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
numData = xlsread('DireccionVelocidadViento.xlsx');
alpha = numData(:,2);
DireccionViento = numData(:,1);
% Plot the data.
hFig1 = figure;
hFig1.WindowState = 'maximized';
plot(alpha, DireccionViento, 'b*-');
grid on;
xlabel('alpha', 'FontSize', fontSize);
ylabel('DireccionViento', 'FontSize', fontSize);
paso = 30;
kstd = 2;
% Define parameters from the equation.
w1 = 10; % Whatever.
z1 = 32;
z2 = 18;
direcs = (0:paso:360)'
numberOfDireccions = length(direcs);
alpha_prom = nan(numberOfDireccions-1, 1); %not a number
hFig2 = figure;
hFig2.WindowState = 'maximized';
for k = 1 : (numberOfDireccions-1)
% Find all indexes more than 0 but less than 30, or more than 30 but less than 60, etc. and is not nan.
validIndexes = (DireccionViento>=direcs(k)) & (DireccionViento<=direcs(k+1)) & ~isnan(DireccionViento); % A vector
% Get the alpha's for those indexes.
alpha_k = alpha(validIndexes); % A vector.
% filtremos un poco antes del promedio
% Get the mean and std dev of the alpha's for those directions.
stdk = nanstd(alpha_k); % A single scalar value.
avek = nanmean(alpha_k); % A single scalar value.
% Ignore outliers and find inliers - those points within +/- 2 standard deviations of the mean.
inlierIndexes = (alpha_k > avek - kstd*stdk)&(alpha_k < avek + kstd*stdk); % kstd desvios estándar
inlierAlphas = alpha_k(inlierIndexes);
% Recompute the mean, now that we're ignoring outliers.
meanInlierAlpha = nanmean(inlierAlphas); % A single scalar value.
alpha_prom(k) = meanInlierAlpha;
% Plot the alphas and mean alpha for this direction range.
% grafico
sk = length(alpha_k);
xk = (1:1:sk);
subplot(4, 4, k)
% Plot the alphas for this direction range with a blue dot and lines connecting them.
plot(xk, alpha_k, '.-b'); %valores de alpha
hold on; % Don't blow away other plots to come.
% Plot the alphas for this direction range with a red star.
plot(xk(inlierIndexes), inlierAlphas, '*r'); %gráficas con desviación estandár en rojo
% Plot a line across at the mean alpha for this range of directions.
yline(meanInlierAlpha, 'Color', 'g', 'LineWidth', 2); %promedio de alpha
legend('alpha', 'inlierAlphas', 'meanInlierAlpha', 'Interpreter', 'none');
caption = sprintf('Direction = %d to %d', direcs(k), direcs(k+1));
title(caption);
xlabel('Index');
grid on;
drawnow;
% Get the wind velocity for this mean alpha and for this range of directions.
w2(k) = w1 / (z1/z2)^meanInlierAlpha;
end
x_direcs = direcs(1:numberOfDireccions-1) + paso/2;
% Plot alpha as function of direccion.
subplot(4, 4, 13:14);
plot(x_direcs, alpha_prom, 'r*-', 'LineWidth', 2) %grafica de alpha promedio con valores de grados
grid on;
title('Alpha as function of Direccion', 'Interpreter', 'none');
xlabel('x_direcs', 'FontSize', fontSize, 'Interpreter', 'none');
ylabel('alpha_prom', 'FontSize', fontSize, 'Interpreter', 'none');
% Plot velocity as function of direccion.
subplot(4, 4, 15:16);
plot(x_direcs, w2, 'r*-', 'LineWidth', 2) %grafica de alpha promedio con valores de grados
grid on;
title('w2 (velocity) as function of Direccion', 'Interpreter', 'none');
xlabel('x_direcs', 'FontSize', fontSize, 'Interpreter', 'none');
ylabel('w2 (Velocity)', 'FontSize', fontSize, 'Interpreter', 'none');
fprintf('Done running %s.m.\n', mfilename);

More Answers (1)

Image Analyst
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
Ana Soph
Ana Soph on 9 May 2020
the height of the values are 32m, the height of the new station is 18m (this is the value that i need) , i have the other months if you need .
Best!!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by