Info

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

Importing txt file using the importdata comand

5 vues (au cours des 30 derniers jours)
googo
googo le 17 Avr 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello,
*1: *
I wrote a function that does some manipulations over a vector strings. Now, I want to apply it on text files.
So let's assume XXX.txt is :
hello world
hello world world
hello world world world
So I wrote:
A = importdata comand ('XXX.txt')
when I run A I get :
A =
'hello world'
'hello world world'
'hello world world'
Now, I want it to be treated as 3 separated vectors of chars. How can I do it? or better question is how to get to one of the vectors? For example: V1 = 'hello world' and V1(1,1)=h
2:
When I tryed to run text files with a lot of text I received this message:
A = importdata('a_lot_of_text.txt')
A =
[1x2568 char]
what does it means? and the first question refers to this also.
Thank's!
  2 commentaires
Friedrich
Friedrich le 17 Avr 2013
Modifié(e) : Friedrich le 17 Avr 2013
When I import the xxx.txt i get what you want right away:
>> A = importdata('XXX.txt')
A =
'hello world'
'hello world world'
'hello world world world'
>> A{1}
ans =
hello world
>> A{1}(1,1)
ans =
h
>> A{1}(1,1:3)
ans =
hel
It seems like that a_lot_of_text.txt has a different format than xxx.txt
googo
googo le 17 Avr 2013
Modifié(e) : googo le 17 Avr 2013
Thank's.
No,it's a txt also.
It's just a big paragraph. For exmaple, I copied this paragraph to notepad:
The human brain has the same general structure as the brains of other mammals, but is larger than any other in relation to body size. Large animals such as whales and elephants have larger brains in absolute terms, but when measured using the encephalization quotient which compensates for body size, the human brain is almost twice as large as the brain of the bottlenose dolphin, and three times as large as the brain of a chimpanzee. Much of the expansion comes from the part of the brain called the cerebral cortex, especially the frontal lobes, which are associated with executive functions such as self-control, planning, reasoning, and abstract thought. The portion of the cerebral cortex devoted to vision is also greatly enlarged in humans.
I saved it as vvv.txt and wrote:
>> B=importdata('vvv.txt')
B =
[1x749 char]

Réponses (0)

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