Good morning
I try to import values from a file, matlab makes a table file from it.
Now I want to use the table values as doubles, such that I can work with it numerically.
I tried
A = table2array(Displacment_u1_u2)
But then I finish up with
A =
1×2 categorical array
-4.5031370E-03 -1.1870213E-01
These values are still not manipulatable.
When I then try
double(A)
I get the values from the 'baskets' they're in,
ans =
1 2
Thus, how do i get the categorical arrays as double values such that I can work with them?

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 1일
편집: Ameer Hamza 2020년 10월 1일

1 개 추천

First, convert to string and then convert to numeric values.
v = categorical([1e-4 1e-6]);
x = arrayfun(@(x) str2double(x), string(v));

댓글 수: 3

Frank Oosterveld
Frank Oosterveld 2020년 10월 1일
works! thanks!
Ameer Hamza
Ameer Hamza 2020년 10월 1일
I am glad to be of help!
Charlie Haimbaugh
Charlie Haimbaugh 2022년 2월 28일
I have issues with str2double and str2num in term of precision. I am trying to convert string gps coordinates from an imported table to numbers, but it brings precision down to 4 decimals. Is there any way around this?

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

추가 답변 (1개)

Campion Loong
Campion Loong 2020년 10월 9일

1 개 추천

Hi Ameer,
If you have R2019a and newer, you can try using readmatrix to directly read the file as numeric:

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by