Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

importing text and integers using textscan and using in a matrix

1 visualización (últimos 30 días)
Jim
Jim el 25 de Jul. de 2012
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentarios

Respuestas (1)

Image Analyst
Image Analyst el 25 de Jul. de 2012
Editada: Image Analyst el 25 de Jul. de 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 comentarios
Image Analyst
Image Analyst el 25 de Jul. de 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 el 25 de Jul. de 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.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by