Plot a graph from arrays

5 ビュー (過去 30 日間)
Alina Abdikadyr
Alina Abdikadyr 2023 年 1 月 26 日
回答済み: Torsten 2023 年 1 月 26 日
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

採用された回答

Star Strider
Star Strider 2023 年 1 月 26 日
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.
.

その他の回答 (1 件)

Torsten
Torsten 2023 年 1 月 26 日
plot(hv, cell2mat(Xm))

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by