The way to do this is to reshape your image into an nx3 matrix where each row correspond to the three colours of a pixel. You can then apply |unique| with the |'rows'| option on this to get your labels. It's then just a matter of reshaping the output. Note that doing the scanning by rows rather than by columns complicate the code somewhat. Also, please, post valid matlab code rather than leaving it to us to generate valid matrix A = cat(3, [22 22 39;89 23 99; 89 69 99], ... it would have been great [10 10 40; 11 11 10; 11 10 10], ... if I could just have [10 10 50; 14 11 10; 14 10 10]) %copy/pasted that from your question [~, ~, labels] = unique(reshape(permute(A, [2 1 3]), [], 3), 'rows', 'stable'); B = reshape(labels, size(A, 2), size(A, 1))' The same code if you do the labeling by column: [~, ~, labels] = unique(reshape(A, [], 3), 'rows', 'stable'); %no need to transpose anymore B = reshape(labels, size(A, 1), size(A, 2)) %no need to transpose either. Answer from Guillaume on mathworks.com
🌐
MathWorks
mathworks.com › matlabcentral › answers › 550888-reshaping-a-complex-3d-array-into-1d-and-back
Reshaping a complex 3D array into 1D, and back - MATLAB Answers - MATLAB Central
June 18, 2020 - I then need to convert it back into its 3D form. The issue here is that the following code destroys the original formatting of the 3D array ... https://www.mathworks.com/matlabcentral/answers/550888-reshaping-a-complex-3d-array-into-1d-and-back#comment_904153
Discussions

How do I transform a 3d vector into a 1d vector?
In your particular case, you should use the squeeze(x) function to remove unnecessary matrix dimension More on reddit.com
🌐 r/matlab
3
3
December 15, 2018
How to convert 3D image to 1D data?
I took the readings for different ... as a 2D array of 5002x8 double. I converted it into a 3D image (.png) and did some processing. Now I want to convert this 3D image back to temp data. How can I do that? ... https://www.mathworks.com/matlabcentral/answers/486383-how-to-convert-3d-image-to-1d-data#comm... More on mathworks.com
🌐 mathworks.com
1
0
October 20, 2019
How to divide a 3D array into one dimensional cell array
Hi, I have a 3x3xn Array which actually contains n times 3x3 matrices. I want to convert it to a one dimensional cell array with n entries (nx1) so that the ith cell contains the ith 3x3 matri... More on mathworks.com
🌐 mathworks.com
1
0
December 25, 2017
How to convert 3D matrix to 1D?
How to convert 3D matrix to 1D?. Learn more about matrix More on au.mathworks.com
🌐 au.mathworks.com
2
0
December 3, 2015
🌐
MathWorks
mathworks.com › matlabcentral › answers › 486383-how-to-convert-3d-image-to-1d-data
How to convert 3D image to 1D data? - MATLAB Answers - MATLAB Central
October 20, 2019 - I took the readings for different ... as a 2D array of 5002x8 double. I converted it into a 3D image (.png) and did some processing. Now I want to convert this 3D image back to temp data. How can I do that? ... https://www.mathworks.com/matlabcentral/answers/486383-how-to-convert-3d-image-to-1d-data#comm...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 374455-how-to-divide-a-3d-array-into-one-dimensional-cell-array
How to divide a 3D array into one dimensional cell array - MATLAB Answers - MATLAB Central
December 25, 2017 - Hi, I have a 3x3xn Array which actually contains n times 3x3 matrices. I want to convert it to a one dimensional cell array with n entries (nx1) so that the ith cell contains the ith 3x3 matri...
Find elsewhere
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1937114-sort-and-rearranged-a-1d-array-to-3d-matrix
Sort and rearranged a 1D array to 3D matrix - MATLAB Answers - MATLAB Central
March 29, 2023 - Hello all, I have matrix with the size of 60x150x150. I have reshaped it into a 1D array and sorted it so the value is in descending order. What I want to do next is rearrange this 1D array back ...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 344638-indexing-3d-matrix-with-three-1d-vector
Indexing 3D matrix with three 1D vector - MATLAB Answers - MATLAB Central
June 13, 2017 - https://www.mathworks.com/matlabcentral/answers/344638-indexing-3d-matrix-with-three-1d-vector#answer_270626 ... I would use the sub2ind (link) function. I am not certain you could do it in one line, but you can get close. ... Sign in to comment. Sign in to answer this question. MATLAB Language Fundamentals Matrices and Arrays Matrix Indexing
🌐
MathWorks
mathworks.com › matlabcentral › answers › 38602-how-to-convert-1d-array-of-2d-matrix-contents-to-3d-array
How to convert 1D-array of 2D-matrix (contents) to 3D-array - MATLAB Answers - MATLAB Central
May 17, 2012 - Below is my code. filename is stored as 1D-array of string type imread(filename): return 2D-matrix (3D in color? -extra: do I have to convert it to gray as 2D for isosurface function?) [filename, pathname, filterindex] = uigetfile('*.png','Select 2D slices', 'multiselect', 'on'); ... Sign in to comment. Sign in to answer this question. Sign in to answer this question. MATLAB Graphics 2-D and 3-D Plots Surfaces, Volumes, and Polygons Volume Visualization Scalar Volume Data
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1709210-transform-2d-array-latitude-into-1d-array-latitude
Transform 2d array latitude into 1d array latitude - MATLAB Answers - MATLAB Central
May 1, 2022 - Reload the page to see its updated state. ... https://www.mathworks.com/matlabcentral/answers/1709210-transform-2d-array-latitude-into-1d-array-latitude ... Hi, i have downlod the climate projection of sea surface temeperature obtained with the cmip6 model. My problem is that i have a 2d array for latitude and longitude and my sst is a 3d array sst(tos, i , j) where
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1901705-how-to-create-a-3d-matrix
How to create a 3D Matrix? - MATLAB Answers - MATLAB Central
January 27, 2023 - In contrast, MATLAB (and numpy) store actual contiguous arrays in memory, that means one single block of numeric data with a specific size. And just like mathematical arrays they must have consistent dimension sizes. You can concatenate a 3D array out 2D matrices by using the CAT() function: