make categorical array out of 4D array

1 view (last 30 days)
Kuno Bruswachtl
Kuno Bruswachtl on 4 Mar 2022
Commented: Kuno Bruswachtl on 10 Mar 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 Comments
Walter Roberson
Walter Roberson on 10 Mar 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 on 10 Mar 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!

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!