Plot a graph from arrays

조회 수: 7 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by