Info
This question is closed. Reopen it to edit or answer.
importing text and integers using textscan and using in a matrix
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 25 Jul 2012
Edited: Image Analyst
on 25 Jul 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 Comments
Image Analyst
on 25 Jul 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?
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!