Plot a graph from arrays

5 visualizzazioni (ultimi 30 giorni)
Alina Abdikadyr
Alina Abdikadyr il 26 Gen 2023
Risposto: Torsten il 26 Gen 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

Risposta accettata

Star Strider
Star Strider il 26 Gen 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.
.

Più risposte (1)

Torsten
Torsten il 26 Gen 2023
plot(hv, cell2mat(Xm))

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by