フィルターのクリア

Re-representing an int list

6 ビュー (過去 30 日間)
Yinan Xuan
Yinan Xuan 2018 年 5 月 1 日
コメント済み: Walter Roberson 2018 年 5 月 1 日
Hi,
I have a super long list like [1 2 3 5 6 7 500 501 503 ... 11589 11590 11591]. I am wondering if I can visualize it in a way like [1:3,5:7,500:503,...,11589:11591]. If I cannot do it in matlab, can I do it in python?
Thank you very much!
  2 件のコメント
Guillaume
Guillaume 2018 年 5 月 1 日
If you write [1:3, 5:7] at the command line it will be automatically displayed as
>> [1:3, 5:7]
ans =
1 2 3 5 6 7
i.e. automatically expanded. I'm not sure if that's what you mean by visualize as there are many different ways to look at the content of a variable in matlab, but if you mean at the command line, no that is not possible.
Note that while there is only one expanded way of displaying the array, there is an infinite way of condensing it.
However, on a related note, see this cody problem I posted several years ago.
Walter Roberson
Walter Roberson 2018 年 5 月 1 日
I have posted code for this in the past, but unfortunately it is probably lost in the masses of other things I have posted.

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

回答 (1 件)

Star Strider
Star Strider 2018 年 5 月 1 日
If your list is a vector of integers from 1 to 11591, with a length of 11591, try this:
List = 1:11591;
N = numel(List);
M = nan(1,ceil(N/3)*3);
M(1:N) = List;
M = reshape(M, 3, [])';
The last element of the ‘M’ matrix is NaN, because the number of elements in ‘M’ must be an integer multiple of the number of columns you want in it (here 3) in order for the reshape function to work.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by