How to expand a matrix depending on the file size?

1 回表示 (過去 30 日間)
sia ben
sia ben 2023 年 1 月 18 日
コメント済み: sia ben 2023 年 1 月 18 日
I want to plot error bars of data that can have different number of elements. But the data always contains four different types and should be plotted in four colors. For example, if data has 16 elements, the colors should be (1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4) and if the data has only 4 elements, the color index should only be (1 2 3 4). How can I have flexible indexing dependent on number of items?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 18 日
Does this work?
y=[1 2 3 4];
n=16;
repelem(y,n/4)
ans = 1×16
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
sia ben
sia ben 2023 年 1 月 18 日
Thanks!

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

採用された回答

Sylvain
Sylvain 2023 年 1 月 18 日
Does this help ?
n = 2;
mycolors = [1*ones(1,n),2*ones(1,n),3*ones(1,n),4*ones(1,n)];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by