Plot a graph from arrays

3 views (last 30 days)
Alina Abdikadyr on 26 Jan 2023
Answered: Torsten on 26 Jan 2023
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 on 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.
.

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

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by