why is this code not running?
3 次查看(过去 30 天)
显示 更早的评论
% Create plots for generator dispatch
figure;
subplot(2, 1, 1);
plot(TimeValue, Pdispatch(:, 1), 'r', 'LineWidth', 2); % Solar
hold on;
plot(TimeValue, Pdispatch(:, 2), 'g', 'LineWidth', 2); % Wind
plot(TimeValue, Pdispatch(:, 3), 'k', 'LineWidth', 2); % Coal
plot(TimeValue, Pdispatch(:, 4), 'b', 'LineWidth', 2); % Gas
plot(TimeValue, Pdispatch(:, 5), 'c', 'LineWidth', 2); % Hydro
title('Generator Dispatch Over Time');
xlabel('Time (hours)');
ylabel('Power Dispatch (MW)');
legend('Solar', 'Wind', 'Coal', 'Gas', 'Hydro');
grid on;
1 个评论
回答(4 个)
VBBV
2023-8-12
plot(TimeValue, Pdispatch(:, 1), 'Color','r', 'LineWidth', 2);
3 个评论
VBBV
2023-8-12
Probably there must be categorical or other form of data for TimeValue matrix.
See this link for more info on how to plot then alike.
https://in.mathworks.com/help/matlab/ref/datetime.html https://in.mathworks.com/help/matlab/categorical-arrays.html
Walter Roberson
2023-10-5
plot(TimeValue, Pdispatch(:, 1), 'r', 'LineWidth', 2); % Solar
is fine. plot() permits a positional linespec after x y pairs, and color letters are permitted in linespec . You would need 'Color' if you were setting a color by other methds such as RGB .
C B
2023-8-12
% Time array (24 hours)
TimeValue = 1:24;
% random data
SolarDispatch = 80 + 5*randn(1, 24);
WindDispatch = 50 + 6*randn(1, 24);
CoalDispatch = 100 + 7*randn(1, 24);
GasDispatch = 20 + 8*randn(1, 24);
HydroDispatch = 30 + 9*randn(1, 24);
Pdispatch = [SolarDispatch; WindDispatch; CoalDispatch; GasDispatch; HydroDispatch]';
I have taken random data like above , but your mat file can be different. please let me know if you are still facing issue. code seems to be ok.
figure;
subplot(2, 1, 1);
plot(TimeValue, Pdispatch(:, 1), 'r', 'LineWidth', 2); % Solar
hold on;
plot(TimeValue, Pdispatch(:, 2), 'g', 'LineWidth', 2); % Wind
plot(TimeValue, Pdispatch(:, 3), 'k', 'LineWidth', 2); % Coal
plot(TimeValue, Pdispatch(:, 4), 'b', 'LineWidth', 2); % Gas
plot(TimeValue, Pdispatch(:, 5), 'c', 'LineWidth', 2); % Hydro
title('Generator Dispatch Over Time');
xlabel('Time (hours)');
ylabel('Power Dispatch (MW)');
legend('Solar', 'Wind', 'Coal', 'Gas', 'Hydro');
grid on;
0 个评论
Star Strider
2023-8-12
What does ‘not running’ mean? What is not working correctly?
When I supply values for ‘TimeValue’ and ‘Pdispatch’ it runs without error —
TimeValue = 0:23;
Pdispatch = rand(24, 5);
figure;
subplot(2, 1, 1);
plot(TimeValue, Pdispatch(:, 1), 'r', 'LineWidth', 2); % Solar
hold on;
plot(TimeValue, Pdispatch(:, 2), 'g', 'LineWidth', 2); % Wind
plot(TimeValue, Pdispatch(:, 3), 'k', 'LineWidth', 2); % Coal
plot(TimeValue, Pdispatch(:, 4), 'b', 'LineWidth', 2); % Gas
plot(TimeValue, Pdispatch(:, 5), 'c', 'LineWidth', 2); % Hydro
title('Generator Dispatch Over Time');
xlabel('Time (hours)');
ylabel('Power Dispatch (MW)');
legend('Solar', 'Wind', 'Coal', 'Gas', 'Hydro');
grid on;
.
0 个评论
SAMWESLIN S
2023-10-5
% Create plots for generator dispatch
figure;
% Subplot for Power Dispatch
subplot(2, 1, 1);
% Plot different generators
plot(TimeValue, Pdispatch(:, 1), 'r', 'LineWidth', 2); % Solar
hold on;
plot(TimeValue, Pdispatch(:, 2), 'g', 'LineWidth', 2); % Wind
plot(TimeValue, Pdispatch(:, 3), 'k', 'LineWidth', 2); % Coal
plot(TimeValue, Pdispatch(:, 4), 'b', 'LineWidth', 2); % Gas
plot(TimeValue, Pdispatch(:, 5), 'c', 'LineWidth', 2); % Hydro
% Title and labels
title('Generator Dispatch Over Time');
xlabel('Time (hours)');
ylabel('Power Dispatch (MW)');
% Legend and grid
legend('Solar', 'Wind', 'Coal', 'Gas', 'Hydro');
grid on;
Make sure that your TimeValue and Pdispatch variables are correctly defined and contain the necessary data, and this code should work as intended in a MATLAB environment.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!