convert table to array or matrix

조회 수: 8 (최근 30일)
hanem ellethy
hanem ellethy 2015년 8월 30일
댓글: hanem ellethy 2015년 9월 2일
I have table with some extracted features like intensity, area, and diameter.these values is real values.
when I convert this table to an array, all data converted to be from 0 to 255 but I need my data in the array exactly as it in the table.....please help
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 8월 30일
What command are you using to convert the table to an array?

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

채택된 답변

Image Analyst
Image Analyst 2015년 8월 30일
I assume you got those measurements from regionprops. regionprops() can now deliver its output directly in table format:
stats = regionprops(BW, 'output', 'table');
If you're using an old version of MATLAB, you can use struct2table().
  댓글 수: 3
Image Analyst
Image Analyst 2015년 8월 30일
Then get in a structure and concatenate into arrays with brackets. That's what I usually do
stats = regionprops(BW, grayImage, 'Area', 'EquivDiameter', 'MeanIntensity');
allAreas = [stats.Area];
allDiameters = [stats.EquivDiameter];
allIntensities = [stats.MeanIntensity];
Those will be row vectors. Of course you could concatenate into one big 2D matrix :
allMeasurements = [allAreas, allDiameters, allIntensities];
but I don't think that would help with the clarity of the program so I wouldn't recommend it. It would just make it more confusing even though there are fewer variables.
hanem ellethy
hanem ellethy 2015년 8월 30일
thank you, it seems I get my way without convertting

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

추가 답변 (1개)

Peter Perkins
Peter Perkins 2015년 8월 31일
There are two ways to converta table to a (numeric in this case) array:
1) call table2array 2) use {} subscripting for the variables you want to extract
You say, "all data converted to be from 0 to 255". Tables are all about mixed data types - one container with doubles, uints, strings, whatever in it. When you "convert to an array", what you're really doing is "converting to a single data type". So by MATLAB's precedence rules, if your table has some uint8's in it, everything (numeric) will be converted to uint8, because that's the only way you can get everything into one homogeneous array.
To get an array of doubles, you'll need to convert the non-double variables to double first.
  댓글 수: 1
hanem ellethy
hanem ellethy 2015년 9월 2일
thanks for your support it works without converting. Best Regards

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by