Making Correlation Plots between variables.

조회 수: 6 (최근 30일)
Bhavick Singh
Bhavick Singh 2021년 9월 8일
답변: Jaimin 2024년 8월 8일
I have voltage, current and power in a table. However, I need only the correlation plot of voltage vs current and voltage vs power. I do not need the histogram or the least square plot. What command or technique should i use to achieve this?

답변 (1개)

Jaimin
Jaimin 2024년 8월 8일
From what I understand, you are trying to plot the correlation between voltage and current, as well as between voltage and power.
For that, you can utilize the scatterfunction, or the plot function provided by MATLAB.
Here, I have attached a sample code using the scatter function related to the issue:
% Example data
voltage = linspace(0, 10, 100); % Voltage ranging from 0 to 10 volts
current = 2 * voltage + randn(1, 100); % Current with a linear relationship to voltage plus some noise
power = voltage .* current; % Power calculated as voltage times current
% Create a figure
figure;
% Scatter plot for Voltage vs Current
subplot(1, 2, 1);
scatter(voltage, current, 'b');
title('Voltage vs Current');
xlabel('Voltage (V)');
ylabel('Current (A)');
% Scatter plot for Voltage vs Power
subplot(1, 2, 2);
scatter(voltage, power, 'r');
title('Voltage vs Power');
xlabel('Voltage (V)');
ylabel('Power (W)');
% Adjust layout
sgtitle('Correlation Plots');
For more information about the “scatter” function, refer to this documentation
For more information about “plot” function, refer to this documentation
I hope this helps you resolve your issue.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by