Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

importing text and integers using textscan and using in a matrix

1 vue (au cours des 30 derniers jours)
Jim
Jim le 25 Juil 2012
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have a text file with 2 cols. Col one is text and col is integer. I want to import the two cols and then be able to manipulate the imported set, eg, randomize the order of the rows. I've tried textscan and xlsread but I cannot work with the imported data in matlab. for example, I have word1 3 word2 5 word3 5 . . . and want to randomize the order of the rows.
  3 commentaires
Jim
Jim le 25 Juil 2012
thanks

Réponses (1)

Image Analyst
Image Analyst le 25 Juil 2012
Modifié(e) : Image Analyst le 25 Juil 2012
Why don't you use dlmread()?
Demo to randomize rows:
% Generate sample data.
m = magic(6)
% Get a random order for the rows.
randomRows = randperm(size(m, 1))
% Extract rows in that random order into a new matrix.
randomized_m = m(randomRows, :)
  7 commentaires
Image Analyst
Image Analyst le 25 Juil 2012
Can't you just use str2double to convert the string version of the numbers into double, and then use sort()? That's seems like the obvious procedure, so I'm sure you already tried that. So what happened when you tried it?
Jim
Jim le 25 Juil 2012
That does not work. The error message is:
Undefined function or method 'str2doule' for input arguments of type 'int32'.
words2 contains {10x1 cell} [10x1 int32]
I'm still relatively new to Matlab.
thanks for your help.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by