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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Ana Soph
Ana Soph il 9 Mag 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?
w1 = wind velocity of the station of 32 m
w2 = wind velocity of the station of 18 m (data that i need)
z1 = height 32 m
z2=height of 18 m
but i don't use it yet, because i have to obtain the alpha for every wind direction that i have and then replace it.
  • Which variable in your code represents the velocity?
sorry, in my code i don't have wind velocity yet, because i don't know how to do that
  • 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?
It is totally fine, i understand, i am plotting the values of alpha, standar deviation and the mean of alpha for all the values, the first graph is only the wind direction (in the X axes(in degrees), and in the Y axes is the mean alpha for this values of wind direction) no any one of those are velocity, xk only is for plot the values of alpha.
  • And in the third plot why are you multiplying the second term by 0? Because meank+0*xk is simply meank.
Yes, it is a trick, 0 * xk generates a vector of the same size as xk, but with zeros inside
Ana Soph
Ana Soph il 9 Mag 2020
Modificato: Ana Soph il 9 Mag 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!

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 10 Mag 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);

Più risposte (1)

Image Analyst
Image Analyst il 9 Mag 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 Commenti
Ana Soph
Ana Soph il 9 Mag 2020
ok, i am sorry , is true, here I attach the corresponding document
Thanks a lot !
Ana Soph
Ana Soph il 9 Mag 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!!

Accedi per commentare.

Categorie

Scopri di più su General Physics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by