이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Multiply array if number is under certain value
조회 수: 1 (최근 30일)
이전 댓글 표시
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))
Radiation = table2array(Data(83:(223),3)) %kW/m^2
PV_radiation = Radiation./1000
T_modul = (T_Pyra)+(PV_radiation/20) %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100)
I_korrektion = 0.988
P_peak = 23947000 %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation %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
답변 (1개)
Mathieu NOE
2022년 3월 22일
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
Peter Lyngbye
2022년 3월 22일
So can i just copy the lower part into my script and it should multiply every value beneath 1.000.000 with 2?
I dont understand the top part... It is supposed to give me an excel were every value above 1.000.000 is not affected.
Best regards
Mathieu NOE
2022년 3월 22일
ok
can you show the updated code and for my info , what are we comparing ? the picture shows 3 vectors (P_out, power , matlab) ... what is the supposed P_out before and after correction in your code ?
Peter Lyngbye
2022년 3월 22일
This is the full code after adding yours:
Data = readtable('Rejstrup Pyra .xlsx'); %Celcius
T_Pyra = table2array(Data(87:(222),8));
Radiation = table2array(Data(87:(222),3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
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
The script is supposed to add temperature and iradiation from a solar park, and via formulas give the power collected from them which is P_out. But becuase of shadows in the park at early ours i need to multiply these values with a correction factor. The data from the excel have 5 minute logs of the radiation and temperature, which i will run through the script and compare to actual pwer readings from the park. I have added one of the excels for iradtioan and temp... I just noticed that actually telling matlab to multiply the early hours instedet of values beneath 1.000.000 would be more correct. I hope u understand what im asking, but a script multiplying for example the readings between 6:30 and 9:30 would be absolutely perfect! it is 24 hour clock
Best regards!
Mathieu NOE
2022년 3월 22일
hello again
the error came because you left my "dummy" data line active in your code
P_out = 1000000 + 80000*randn(10,1); % dummy data
that was of course to be removed
now it's working fine ,
but not yet to the point of being matching the new request for correction between 6:30 and 9:30
Data = readtable('Rejstrup Pyra .xlsx'); %Celcius
T_Pyra = table2array(Data(87:(222),8));
Radiation = table2array(Data(87:(222),3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
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
Peter Lyngbye
2022년 3월 22일
Okay got it. But i dont understand the graph u show... I need to compare the graph to another graph which is why i need to be able to correct the data between 6:30 and 9:30 by a simple correction factor :/
i have added a picture so it is easier to understand my problem. The blue line is my calculations coming from matlab going into excel. As u can see i need correction in the start (6:30-9:30).
I am really appreciating ur help!
Peter Lyngbye
2022년 3월 22일
I understand ur code, but i need it to get tranfered into my excel with the other data.
This is the bottom of my code, where the data gets into excel. It is here each data point beneath 1.000.000 needs to be corrected, so when i plot my function in excel it will have the corrrection
table_name=table(P_out);
filnavn='Beregnet P_available fra Rejstrup.xlsx';
overskrift='P_available';
writetable(table_name,filnavn,'Sheet',overskrift)
Mathieu NOE
2022년 3월 22일
I was just finishing to modify your code for the correction in amplitude (x2 befoe 9:30 AM)
this is the code (a bit improved) and the result
but this is not what your last picture is telling me . It's a different correction method
so far the code is as pr your initial request
Data = readtable('Rejstrup Pyra .xlsx'); %Celcius
ind_start = 87;
ind_stop = 222;
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(Data.GeneratedOn);
T_Pyra = table2array(Data(:,8));
Radiation = table2array(Data(:,3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
plot(Data_time,P_out)
hold on
ind = 116 - ind_start; % find time line corresponding 9:30 AM
P_out(1:ind) = P_out(1:ind)*2; % correction (put the right correction factor here)
plot(Data_time,P_out,'-*')
legend('before correction','after correction');
hold off
Mathieu NOE
2022년 3월 22일
Please clarify
this is your picture a bit modified by myself (the red line is the extrapolation of the blue line for the first hours) : do you mean this is what you want to achieve ?
but the P_out graph I get even before any correction does not show this initial drop
this is what I get when I start the plot even earlier
Data = readtable('Rejstrup Pyra .xlsx'); %Celcius
ind_start = 87-40;
ind_stop = 222;
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(Data.GeneratedOn);
T_Pyra = table2array(Data(:,8));
Radiation = table2array(Data(:,3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
plot(Data_time,P_out)
Mathieu NOE
2022년 3월 22일
hmmm
this is how your Data table names are defined in my workspace (I run R2020b)
maybe the name of the first columns of Data is different in your matlab. Please correct on your side if you have a different name
Peter Lyngbye
2022년 3월 22일
I want my calculation form matlab (the blue line) to be as close to the gray line (real life data). To do this i simply want to correct the data i get from my matlab script by correcting it primaryli in the start as the two lines are far apart here. I would think the script would look like my original script with something like:
- Between two points taking from my excel (showing radiation and temperature at some logging time) the calculations done by the script are multiplied by some factor for example 2. This way the blue and gray line will be closer to each other hence be more correct.
I
Peter Lyngbye
2022년 3월 22일
Yezzus christ... My whole matlab is a total mess right now... There are many "workspaces"... Can u send ur matlab model?
Mathieu NOE
2022년 3월 22일
Sorry but the correction you want is not a factor 2. it much less than that (and it varies with the time value) but I cannot guess it because the grey reference line is not supplied in your data ...
also I don't understand why the blue should match the grey curve simply for the appearance , you are introducing a bias on purpose in your code just to make things look better ??
In the mean time I fixed the previous problem (Unrecognized table variable name 'GeneratedOn'.)
Data = readtable('Rejstrup Pyra .xlsx','VariableNamingRule' ,'preserve'); %Celcius
ind_start = 87-40;
ind_stop = 222;
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));
Radiation = table2array(Data(:,3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
plot(Data_time,P_out)
Mathieu NOE
2022년 3월 22일
ok
let's start again from the beginning
where are the data relative to the grey (reference) and your data (blue)
I cannot see anything like the blue line with the initial drop
I wonder if your matlab code is about is the grey curve and not the blue ??
Peter Lyngbye
2022년 3월 22일
Yeah it is defenetly a lot less than 2, but i will try and go less until the curve fits. The thing is, that i work for a solar company, and because of the low rising sun in the morning the poanel shadow for each other causing my power calculations to fail. This is why i want to introduce this bias. This is true for every solar park we have, and therefore i can use the same correction factor, i just need to find the perfect "fit" so to say
Peter Lyngbye
2022년 3월 22일
Okay.... From the start... The value of the correction factor deos not amtter right now. It should actually be under 1 since the power i calculate at these logs are higher than the actual power i am getting from the solar park. The blue line is comes from the data matlab calculates based on temp and radiation at the different logs.
Peter Lyngbye
2022년 3월 22일
As u can see on the picture i now need to correct the later stages of the day around 16:00-18:30
Mathieu NOE
2022년 3월 22일
okay
it's my turn to become nuts ... :) I still don't get what you want to correct from the P_out generated by the matlab code.
The top plot is your curves , the bottom one is the full 24 hours of P_out as it comes without any further corrections beside what you have already coded
so what correction in the lower plot do you want to do ? that is still unclear to me - make a handheld sketch if you want.
code used for the lower plot :
clc
clearvars
Data = readtable('Rejstrup Pyra .xlsx','VariableNamingRule' ,'preserve'); %Celcius
[m,n] = size(Data);
ind_start = 1; % 87-40
ind_stop = m; % 222
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));
Radiation = table2array(Data(:,3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
plot(Data_time,P_out)
Mathieu NOE
2022년 3월 22일
seems I get some of your comments much earlier in my outlook vs here in the forum, which make things a bit complicate to follow
Peter Lyngbye
2022년 3월 22일
편집: Peter Lyngbye
2022년 3월 22일
Ill try to explain step by step hehe,
- I have and excel were i have the 100% correct power is shown which is illustrated by the grey curve.
- The blue curve is my calculations done on temperature and radiation achieved over the same day the grey curve were formed. This means that if my script were perfect, the blue line would be exactly like the grey line.
- BUT the blue line i get is a bit shiftet in the early hours which is were i need to correct it by some 0.97 ISH factor so that it will compensator for the shadow which occours in the early mornings due to the sun being low in the sky.
- The shadows causes my power calculations to be slighty higher. This is exactly why i need this correction factor :)
Peter Lyngbye
2022년 3월 22일
Also i understand why u are confussed since the curve which is corrected inside the matlab is the P_out calculated curve (the blue line) and not the grey curve which is plottet i my own excel... I have now added the excel.. This shows the true power generated over a day. This is what should be included inside the script instead of the: "P_out(1:ind)" it should be the excel data.
It is the collon B which has the power data in watt.. The other data is just inverter data which is not relevant. The collon B makes a curve which should simply be the curve which i need to correct my "P_out(1:ind)*0.97" too.
Mathieu NOE
2022년 3월 22일
ok
this is where you should have started first
I took your last excel file (I removed the columns above B to speed up the code) into consideration
now I can draw the two lines (and understand the purpose of the code)
you can do all modifications you want up to force the blue to match the grey (simply compute the amplitude ratio at each time interval... or build a strategy around that)
so far it seems now you have reached your target...
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));
Radiation = table2array(Data(:,3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %Watt
% heavy correction : make the blue match exactly the grey
cor_factor = P_out_ref./(P_out+eps); % + eps to avoid division by zero !
P_out_corrected = P_out.*cor_factor;
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 (100% corrected)');
Mathieu NOE
2022년 3월 22일
the size of the Data table , but yes I don't use it in the code (in the last version) so maybe you have a warning but the code runs ok
Peter Lyngbye
2022년 3월 22일
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
2022년 3월 22일
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));
Radiation = table2array(Data(:,3)); %kW/m^2
PV_radiation = Radiation./1000;
T_modul = (T_Pyra)+(PV_radiation/20); %Celcius
T_korrektion = 1-(T_modul-T_Pyra).*(0.40/100);
I_korrektion = 0.988;
P_peak = 23947000; %watt
P_out = P_peak.*T_korrektion.*I_korrektion.*PV_radiation; %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)');
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)