フィルターのクリア

why is this code not running?

2 ビュー (過去 30 日間)
Oyedeji
Oyedeji 2023 年 8 月 12 日
コメント済み: Walter Roberson 2023 年 10 月 5 日
% 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 件のコメント
C B
C B 2023 年 8 月 12 日
can you upload content of Pdispatch and TimeValue also what error are you facing ?

サインインしてコメントする。

回答 (4 件)

VBBV
VBBV 2023 年 8 月 12 日
plot(TimeValue, Pdispatch(:, 1), 'Color','r', 'LineWidth', 2);
  3 件のコメント
VBBV
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
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
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;

Star Strider
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;
.

SAMWESLIN S
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
Unrecognized function or variable 'TimeValue'.
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.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by