How to convert a numeric array to a table.I want the first row of data of the array to be J and the second row of data to be K in a table T[J K];

조회 수: 1 (최근 30일)
>> A=imread('C:\Users\ADMIN\Desktop\canada.bmp');
>> level=graythresh(A);
>> B=im2bw(A);
>> O=imcontour(B);
I'm building this code and the last command returns an array wich has two rows of data!These data are the points of contoured image invariants.I want to create a table which will take the first row of data as J and the second row as K in a new table T[J K];Don't mind if it's double or unit8 or something else.Please help!!

채택된 답변

Guillaume
Guillaume 2016년 8월 29일
array2table(O.', 'VariableNames', {'J', 'K'});
Single letter variable names / column names are not good practice. Use variable names that have meaning.
  댓글 수: 4
Guillaume
Guillaume 2016년 8월 29일
Please, see the help on working with tables
mytable = array2table(O.', 'VariableNames', {'J', 'K'});
mytable(1, :) %return 1st row of mytable as a table
mytable.J(1) %return 1st element of column J

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 29일
A=randi(10,2,5)
names={'J','K'}
cell2table(num2cell(A'),'VariableNames',names)
  댓글 수: 2
Guillaume
Guillaume 2016년 8월 29일
There's no need to go through a cell array. array2table will directly convert all columns of a matrix into table columns.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by