필터 지우기
필터 지우기

How to change data type of table in matlab

조회 수: 11 (최근 30일)
Iram Shahzadi
Iram Shahzadi 2018년 11월 12일
댓글: Iram Shahzadi 2018년 11월 12일
I am reading a spreadsheet with 2 columns using readtable command in Matlab. Both columns of the table are read as a string. How two change the datatype of a second column to double.
  댓글 수: 2
Stephen23
Stephen23 2018년 11월 12일
"How two change the datatype of a second column to double."
Most likely if the data could be imported as numeric then it already would be... what kind of values are in those columns?
If you can, please upload the spreadsheet by clicking the paperclip button.
Iram Shahzadi
Iram Shahzadi 2018년 11월 12일
Thank you for help. Here is the sheet. The first variable is path to Image and second variable 'patient' is some specific location in Image. I want the location to be imported as [1*4 double].

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

채택된 답변

Guillaume
Guillaume 2018년 11월 12일
Really, you should change the way you store your data in the spreadsheet. As it is you're losing most of the benefit of the spreadsheet format. Even in excel, you wouldn't be able to use those numbers as they're stored as text.
One of the many ways of extracting the numbers from the text:
t = readtable('book1.xlsx');
t.patient = cellfun(@str2double, regexp(t.patient, '\d+', 'match'), 'UniformOutput', false)
If you didn't have those brackets [] around the text and the numbers had beens separated by spaces, it would have been easier.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 12일
  댓글 수: 1
Iram Shahzadi
Iram Shahzadi 2018년 11월 12일
I want to change the second variable to double type. I used str2double but all entries under the second variable changed to NaN. Here is what i used
T = readtable('Book1.xlsx') variableNames = T.Properties.VariableNames; T.(variableNames{2}) = str2double(T.(variableNames{2}));

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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by