Problem 552. Cell Array Inception?
Jimmy is a beginning MATLAB student who is trying to read in a text file and build a cell array of strings, where A{k} is the kth line of the text file. He writes the following code, and is confused when it doesn't work:
fid = fopen('myfile.txt','r'); A = {}; while ~feof(fid) A = {A fgetl(fid)}; end
What he finds is that after the loop, A only has two components, no matter what the file length. The second component is the last line of the file, and the first component is another cell array! He then realizes that A{1} also has two components, where the second component is the second-last line of the file and the first component is yet another cell array!
Your task: write a function to undo this "cell-array Inception" and return the proper cell array of strings that Jimmy is looking for. Implement B = unInception(A), where A is the cell array as returned by Jimmy's code.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers29
Suggested Problems
-
Equidistant numbers containing certain value in an interval
87 Solvers
-
Back to basics 9 - Indexed References
441 Solvers
-
Compress strings (not springs)
205 Solvers
-
Getting the indices from a matrix
648 Solvers
-
Find Index of maximum Value and maximum Value of a vector
165 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!