how to read text file into table ??

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
Walter Roberson on 16 Jul 2020
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

i guess thats what i need thnx alot i searched how to use it but i didn't understand
what are your fields? A small sample would help
i have this file to open
fileID = fopen('Copy_of_alice.txt','w');
fprintf(fileID,'%s',A);
fclose(fileID);
and then i was asked to store it in a table and that file containes only characters all of this and more to do huffman compression
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 ?
this is not the whole programm
first i opened a file that contains text
then i was told to write it in another file with characters only which is A
A is long line of characters
so now i have file with characters only
the table enteries are supposed to be the character and its probability
character ' b' 0.0137 the probability
its not for words only characters
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().
thanx Walter Robenson for ur time and i will try to use your hint

Sign in to comment.

Categories

Products

Release

R2009a

Asked:

on 16 Jul 2020

Commented:

on 21 Jul 2020

Community Treasure Hunt

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

Start Hunting!