# Multiply array if number is under certain value

12 visualizaciones (últimos 30 días)
Peter Lyngbye el 22 de Mzo. de 2022
Comentada: Mathieu NOE el 22 de Mzo. de 2022
Im using a script to calculate power from two varaiables. Though i need to multiply my power (P_out) with a certain value (for example 2) if the value is under 1.000.000 to correct my data...
So i have 144 numbers, and all numbers beneath 1.000.000 needs to be multiplied by 2. Maybe 30 of these values are beneath 1.000.000...
How do i do this? Hope someone knows this
This is the code:
Data = readtable('Rejstrup Pyra .xlsx'); %Celcius
T_Pyra = table2array(Data(83:(223),8))
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100)
I_korrektion = 0.988
P_peak = 23947000 %watt
^^^^^^^^
This is my values for my power, where every value beneath 1.000.000 needs to be multiplied with 2.
Exporting it to excel (not relevant):
table_name=table(P_out1)
filnavn='Beregnet P_available fra Rejstrup.xlsx'
overskrift='P_available'
writetable(table_name,filnavn,'Sheet',overskrift)
Best regards
Peter
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Mathieu NOE el 22 de Mzo. de 2022
hello
this is very simple - see below :
P_out = 1000000 + 80000*randn(10,1); % dummy data
plot(P_out)
hold on
ind = P_out<=1000000; % find values below 1000000
P_out(ind) = P_out(ind)*2; % correction (put the right correction factor here)
plot(P_out,'-*')
hold off
##### 29 comentariosMostrar 27 comentarios más antiguosOcultar 27 comentarios más antiguos
Peter Lyngbye el 22 de Mzo. de 2022
This is perfect!
Only last thing i need is this adjustment but for the other half of the curve (late hours):
ind = 130 - ind_start; % find time line corresponding 9:30 AM
P_out(1:ind) = P_out(1:ind)*0.97; % correction (put the right correction factor here)
Right now it only adjust the early hours :/
Mathieu NOE el 22 de Mzo. de 2022
ok
I put back those lines in the code (see below) , but I have a hard time to see what the 0.97 makes as an improvement ?? or did I forgot another piece of code from the past ?
this is not doing any shift in the early hours...
see figure 1 (below)
figure 2 is simply the "heavy" correction method I already posted above
clc
clearvars
%% reference data (grey)
Data_ref = readtable('Rejstrup Effekt.xlsx','VariableNamingRule' ,'preserve'); %Celcius
% [m,n] = size(Data_ref);
ind_start = 60; %
ind_stop = 222; %
Data_ref = Data_ref(ind_start:ind_stop,:); % retrict all table data between two time indexes from 7:10 AM to 18:25 PM
Data_ref_time = datetime(table2array(Data_ref(:,1)));
P_out_ref= table2array(Data_ref(:,2));
plot(Data_ref_time,P_out_ref)
%% measurement (blue, to be corrected)
Data = readtable('Rejstrup Pyra .xlsx','VariableNamingRule' ,'preserve'); %Celcius
% [m,n] = size(Data);
Data = Data(ind_start:ind_stop,:); % retrict all table data between two time indexes from 7:10 AM to 18:25 PM
Data_time = datetime(table2array(Data(:,1)));
T_Pyra = table2array(Data(:,8));
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
%% basic correction
P_out_corrected = P_out; % init P_out_corrected
ind = 116 - ind_start; % find time line corresponding 9:30 AM
Data_ref_time(ind)
P_out_corrected(1:ind) = P_out_corrected(1:ind)*0.97; % correction # 1 (put the right correction factor here)
figure(1),
plot(Data_ref_time,P_out_ref,'k',Data_time,P_out,'b',Data_time,P_out_corrected,'c*')
legend('ref (grey)','blue (uncorrected)','blue (corrected)');
%% full correction (remove code below if necessary)
% make the blue match exactly the grey
P_out_corrected = P_out; % init P_out_corrected
ind = P_out<eps;
P_out_ref(ind) = 0; % avoid very high (inf) cor_factor due to division by eps !
cor_factor = P_out_ref./(P_out+eps); % + eps to avoid division by zero if P_out = 0 !
P_out_corrected = P_out_corrected.*cor_factor;
figure(2),
plot(Data_ref_time,P_out_ref,'k',Data_time,P_out,'b',Data_time,P_out_corrected,'c*')
legend('ref (grey)','blue (uncorrected)','blue (corrected)');

Iniciar sesión para comentar.

### Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by