Multidimensional array to (multidimensional) table.
15 ビュー (過去 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 で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!