Multidimensional array to (multidimensional) table.
조회 수: 16 (최근 30일)
이전 댓글 표시
I have a 3D array from a Tiff image file. The 3 dimensions are (x,y,[R, G, D]), 500x500x3. The RGDs are unsigned integers. I would love to store more property data of different types (i.e double) at the x,y positions. It seems a 3D table could accomplish this, but it does not seem MATLAB has this functionality. Am I best served to have a bunch of 500x500xN arrays for each property/data type? Should I convert the 3D array (x,y,[R, G, D]) to a table with columns x, y, R, G, D, N, M ... It seems there are some operations that are easier to perform in a table than to multiple arrays, such as searching for values in one column and then performing operations on other columns.
If converting to a table seems like a good option, is there a fancy matrix/array method for doing this, instead of the only way I could figure out using embedded for loops like the following. RGB is the original 500x500x3 array. Sorry I do not know how to use this editor.
tableline=0;
tiftable = zeros(size(RGB,1)*size(RGB,2),3); %this will be the new 250000x3 array of RGBs
for r = 1:size(RGB,1) % for all pixel rows
for c = 1:size(RGB,2) % for all pixel columns
tableline = tableline+1;
xpixel(tableline) = c;
ypixel(tableline) = r;
tiftable(tableline,:)=RGB(r,c,:);
end
end
graintable = array2table([xpixel,ypixel,tiftable],'VariableNames',{'Xpixel','Ypixel','R_orig','G_orig','B_orig'});
댓글 수: 0
답변 (1개)
Rajani Mishra
2020년 5월 26일
array2table() function is used to covert a matrix to table, but it does not accepts 3-D matrix (image in this case) as an input arguement. So you can convert data (example image bands - R,G,B or any other property data) to a matrix where columns have required data and then use array2table for transforming to a table
Refer here for documentation of arra2table function : https://www.mathworks.com/help/matlab/ref/array2table.html
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!