Plot a graph from arrays

5 vues (au cours des 30 derniers jours)
Alina Abdikadyr
Alina Abdikadyr le 26 Jan 2023
Hello everyone! Please help me to plot a graph
So I have hv = [0,2,4,6,8], and 5×2 cell array
Xm =
{[54.8765]} {[15.8544]}
{[55.3118]} {[19.0629]}
{[55.2927]} {[23.1122]}
{[54.4031]} {[28.4851]}
{[50.9514]} {[36.8417]}
I need to plot a graph of hv versus Xm
For example for hv=0, Xm=54.8765 and 15.8544 and so on

Réponse acceptée

Star Strider
Star Strider le 26 Jan 2023
Try something like this —
hv = [0,2,4,6,8];
Xm = [
{[54.8765]} {[15.8544]}
{[55.3118]} {[19.0629]}
{[55.2927]} {[23.1122]}
{[54.4031]} {[28.4851]}
{[50.9514]} {[36.8417]}];
X = cell2mat(Xm).'; % Convert To Matrix & Transpose
figure
plot(X, ones(size(X,1),1)*hv, '.-', 'LineWidth',1) % Create Multiples Of 'hv' & Plot (Can Also Use 'repmat' For This)
xlabel('Xm')
ylabel('hv')
ylim(ylim+[-1 1]*0.5)
figure
plot(hv, X, '.-', 'LineWidth',1) % Reversing The Plot Arguments
xlabel('hv')
ylabel('Xm')
figure
plot(ones(size(X,1),1)*hv, X, '.-', 'LineWidth',1) % Reversing The Plot Arguments
xlabel('hv')
ylabel('Xm')
xlim(xlim+[-1 1]*0.5)
I added the ylim call in the second plot (changed to an xlim call in the third plot) to make the lines on the ends easier to see.
The first plot is of ‘hv’ versus ‘Xm’ and the last two are ‘Xm’ versus ‘hv’ since I’m not certain what you want.
.

Plus de réponses (1)

Torsten
Torsten le 26 Jan 2023
plot(hv, cell2mat(Xm))

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by