Effacer les filtres
Effacer les filtres

Re-representing an int list

6 vues (au cours des 30 derniers jours)
Yinan Xuan
Yinan Xuan le 1 Mai 2018
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 commentaires
Guillaume
Guillaume le 1 Mai 2018
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 le 1 Mai 2018
I have posted code for this in the past, but unfortunately it is probably lost in the masses of other things I have posted.

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 1 Mai 2018
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.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by