how to read text file into table ??
Show older comments
i want to read text file into table but i cant use readtable neither xlsread cz i have matlab 2009 so any suggestions ??
Answers (1)
Walter Roberson
on 16 Jul 2020
0 votes
table() objects did not exist in R2009* so you cannot read into a table.
xlsread() did exist in R2009* . However, if you are not using Windows with Excel installed, then in that release you were limited to pure numeric files.
In your release, it might perhaps have been most appropriate to use textscan()
7 Comments
narimen boucenna
on 16 Jul 2020
Walter Roberson
on 16 Jul 2020
what are your fields? A small sample would help
narimen boucenna
on 16 Jul 2020
Walter Roberson
on 16 Jul 2020
What datatype is A ? Is it a character vector that has embedded newline characters? Your code would not work if A is a cell array, and you do not output newline characters.
If you already have the data in memory, why are you writing it to a file?
When you store the data in a "table", then what are the entries to be put in the table? Are you expecting to split it up by words and then do huffman compression based upon the word frequencies? If so then the only reason to use a table() object would be because it was required to do so by the assignment, and if it is required to do so by the assignment then you simply cannot complete the assignment with R009a.
If you are needing to split into words, then you need to carefully define what a "word" is. Is "Huffman" a different word than "huffman" ? How many words are there in
"T'is the 101th season for foregiving and spot-checking word-of-mouth," the mouth's lips said.
and exactly what are they ?
narimen boucenna
on 17 Jul 2020
Walter Roberson
on 17 Jul 2020
You do not need table() objects, then. You need at most a vector of characters, and a corresponding vector of counts, and you would turn that into a vector of probabilities.
You can fopen()/fread()/fclose() to retrieve the characters from the file, or you can use fileread() to get them. But they will be the same as A, so the only reason to write to a file is because the assignment requires it.
Hint: unique() the character vector. accumarray() the third output of unique().
narimen boucenna
on 21 Jul 2020
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!