why is this code not running?
조회 수: 2 (최근 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!