Graphing an array by largest row to smallest row

1 回表示 (過去 30 日間)
Gabriel
Gabriel 2023 年 4 月 25 日
回答済み: dpb 2023 年 4 月 25 日
I would like to graph an array, let's call it output_array, by graphing its largest (in terms of nonzero entries) row first, then graphing the next largest until the last row to graph is the smallest row.
For instance: output_array = [1,2,3; 1,2,3,4,5; 1,2,3,4];
And it would graph the second vector first, then the third vector, then the 1st vector last. Is there an easy way to do this?
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 4 月 25 日
Tthe output_array you mentioned will not be defined as there is a dimension mismatch, see below
y = [1,2,3; 1,2,3,4,5; 1,2,3,4]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
You can either pad them with zeros or NaNs or define a cell array.
And what exactly do you mean by graphing?

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

回答 (1 件)

dpb
dpb 2023 年 4 月 25 日
output_array = {[1,2,3]+0; [1,2,3,4,5]+0.1; [1,2,3,4]+0.2};
[~,ix]=sort(cellfun(@numel,output_array),'descend');
ix=num2cell(ix(:));
hold on
cellfun(@(c,i)plot(c,'x-','DisplayName',"Line "+i),output_array,ix)
legend('location','northwest')
Had to introduce an offset to avoid all points being identical...

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by