how to use plotyy with x-axis cell data type ruther than double.

5 ビュー (過去 30 日間)
Elias Salilih
Elias Salilih 2023 年 8 月 7 日
コメント済み: Voss 2023 年 8 月 15 日
I would like to plot a double axis figure using plotyy. the x-axis is cell type while the two y-axises are double type
x={10:00; 11:00; 12:00; 13:00}
y1=[1 2 3 4]
y2=[4 5 6 7]

回答 (1 件)

Voss
Voss 2023 年 8 月 7 日
I assume that x is not a cell array of empty arrays, as in:
x={10:00; 11:00; 12:00; 13:00}
x = 4×1 cell array
{1×0 double} {1×0 double} {1×0 double} {1×0 double}
but rather a cell array of datetimes, as in:
x=num2cell(datetime({'10:00'; '11:00'; '12:00'; '13:00'},'InputFormat','HH:mm','Format','HH:mm'))
x = 4×1 cell array
{[10:00]} {[11:00]} {[12:00]} {[13:00]}
In that case, you can plot like this:
y1=[1 2 3 4]
y1 = 1×4
1 2 3 4
y2=[4 5 6 7]
y2 = 1×4
4 5 6 7
x_plot = [x{:}]
x_plot = 1×4 datetime array
10:00 11:00 12:00 13:00
plotyy(x_plot, y1, x_plot, y2)
  3 件のコメント
Voss
Voss 2023 年 8 月 10 日
% a cell array of character vectors:
tim = {
'10:00'
'10:15'
'10:30'
'10:45'
'11:00'
'11:15'
'11:30'
'11:45'
'12:00'
'12:15'
'12:30'
'12:45'
'13:00'
'13:15'
'13:30'
'13:45'
'14:00'
};
% convert to a datetime array:
x = datetime(tim,'InputFormat','HH:mm');
% some y values to plot with
y1=1:numel(x);
y2=3:numel(x)+2;
% plot
plotyy(x, y1, x, y2)
Voss
Voss 2023 年 8 月 15 日
@Elias Salilih: Did this answer work for you?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by