Comparing difference between two tables
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi guys,
I am having some trouble comparing two data tables (Residential_Load & Solar_Data) both tables are 48x1. When using the the code below I keep getting a subscripting error however when I fix the subscripting error I get an error using the greater than or Less than functions.
I was wondering if there was any way to fix these issues of if there is an error in my code?
Cheers
% Defining parameter
t = (0:0.5:23.5);
% Comparing differnce between Res Load and Solar Data plotting them to Battery Load
for i = 1:length(t)
if Residential_Load(i) > Solar_Data(i)
Battery1(i,:) = Residential_Load(i) - Solar_Data(i);
else Residential_Load(i) < Solar_Data(i)
Battery1(i,:) = Solar_Data(i) - Residential_Load(i);
end
end
figure(1);
xlabel('Time (hr)')
ylabel('Power (MW')
plot(Battery1,Solar_Data,Residential_Load);
legend('Battery','Solar Power','Residential Load');
hold on;
0 Kommentare
Antworten (1)
Walter Roberson
am 1 Okt. 2022
If you mean that they are table() objects, then you cannot index a table object using only a single subscript. You can, however, index a variable within a table using only a single subscript. For example if the tables had a variable named Wattage then
if Residential_Load.Wattage(i) > Solar_Data.Wattage(i)
However I recommend that you learn to use logical indexing.
In this particular case you do not need any tests: you could do
Battery1 = abs(Solar_Data.Wattage - Residential_Load.Wattage);
However it is not clear to me why the battery value would be positive in both cases; I would tend to think that
Battery1 = Solar_Data.Wattage - Residential_Load.Wattage;
which would be negative for the times that the load exceeds the solar incidence.
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!