Borrar filtros
Borrar filtros

make categorical array out of 4D array

2 visualizaciones (últimos 30 días)
Kuno Bruswachtl
Kuno Bruswachtl el 4 de Mzo. de 2022
Comentada: Kuno Bruswachtl el 10 de Mzo. de 2022
hi,
When I want to use the cross-entropy solver in matlab, I have to use the classificationlayer at the end of my layers and therefore the responses have to be a categorical array. My response array has the size of [1 1 500 7000] where the last two indexes are the the scale of the sample(500) as well as the number of observations (7000).
For using this as a categorical response, I know that is has to be in the form of nx1, as noted in the documantation. However, I don´t how to extract my response array to a categorical one. Any Ideas?
Thanks in advance!
  6 comentarios
Walter Roberson
Walter Roberson el 10 de Mzo. de 2022
You would create either a 500 x 7000 or 7000 x 500 array (different toolbox functions need different ways.)
You would also want a vector of length 7000 indicating which class each sample belongs to. Either you already have that information somewhere, or else it is implicit, such as knowing that (for example) you might have 7 classes with 1000 samples each. You could then use
C = reshape(repmat(categorical(1:NumberOfCategories), 7000/NumberOfCategories, 1),[],1) %OR
C = reshape(repmat(categorical(1:NumberOfCategories), 1, 7000/NumberOfCategories),[],1)
depending how the data is arranged.
Kuno Bruswachtl
Kuno Bruswachtl el 10 de Mzo. de 2022
I think I got it now!
I really have to thank you Walter for your help and time. It means a lot to me, you made my day!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by