0

I have a textdata {} Total number of rows 5.4 million with 3-4 digit integers. I wish to convert them to int on MATLAB.

I tried using x = str2num(total_data(1:end,:)) but it didnt work.

3 Answers 3

1

To return integers , you have to add a prefix and suffix to the string...

>> c = '1234567'

c =

1234567

>> class(c)

ans =

char

>> result = str2num(c)

result =

 1234567

>> class(result)

ans =

double

>> result = str2num(['int32(' c ')'])

result =

 1234567

>> class(result)

ans =

int32
Sign up to request clarification or add additional context in comments.

Comments

0
b = cellfun(@(x)str2double(x), total_data);

Comments

0

I would do something like this:

%Test data
N = 1e4;
textdata = cell(N,1);
for ix = 1:N
    textdata{ix} = num2str(ix);
end

%Convert to integers
dataAsInts = zeros(size(textdata),'int32');
for ix = 1:N
   dataAsInts(ix) = int32(sscanf(textdata{ix},'%d'));
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.