Making Correlation Plots between variables.

7 views (last 30 days)
Bhavick Singh
Bhavick Singh on 8 Sep 2021
Answered: Jaimin on 8 Aug 2024
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?

Answers (1)

Jaimin
Jaimin on 8 Aug 2024
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.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!