How to store multiple y-data of arbitrary length for a given x and plot?

1 回表示 (過去 30 日間)
Udvas.C
Udvas.C 2019 年 12 月 4 日
コメント済み: Udvas.C 2019 年 12 月 4 日
I have a two column data where the each element of the second column have arbitrary length. e.g.
X=[1 2 3 4 5]'
Y= [[1 2 3] [1] [] [1 2 10 4] [1 5 2 0 3]]'
How to store this type of y-data in matlab and plot both X vs Y and Y vs X in a scatter plot? i.e. there should be three points on the graph for X=1, no point for X=0 and so on. Note: There can be no elements in some of the arrays of y.
Thanks

採用された回答

Raj
Raj 2019 年 12 月 4 日
編集済み: Raj 2019 年 12 月 4 日
X=[1 2 3 4 5]';
Y= {[1 2 3] [1] [] [1 2 10 4] [1 5 2 0 3]}';
for ii=1:numel(X)
scatter((repelem(X(ii),numel(cell2mat(Y(ii))))),cell2mat(Y(ii)))
hold on
end
  7 件のコメント
Raj
Raj 2019 年 12 月 4 日
Something like this:
Y=[1 2 3 4 5]';
X= {[1 2 3] [1] [] [1 2 10 4] [1 5 2 0 3]}';
for ii=1:numel(X)
scatter(cell2mat(X(ii)),repelem(Y(ii),numel(cell2mat(X(ii)))))
hold on
end
Udvas.C
Udvas.C 2019 年 12 月 4 日
Yes, it worked. Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by