Reading in file as cell array in a two dimensional [1x1] structure
Ältere Kommentare anzeigen
I am currently having an issue with importing a file in the proper format for a program that I did not write (and the person who wrote it is long gone). This program was written using the MatLab GUI in mind, but I have to use it via code only (I have no formal Matlab training).
The issue is this: The program expects the input of a certain variable to be a 2-dimensional cell array of string vectors, i.e., a 40x10 cell array (each containing only one element of the array). When using the GUI, import is simple: I simply open the file via 'Import Data', highlight the 40x10 region, and import as a cell array. This creates a 40x10 cell array in the 'Workspace'.
When I try to import the file, the program fails. I believe this is because the file is being imported as 40 10x1 arrays, which is not what the program expects. How do I alter my code to achieve a 40x10 cell array?
CellArray = textscan(FileName,'%s%s%s%s%s%s%s%s%s%s','Delimiter',',');
Above is just one example of the import code I have attempted, but I've tried using 'fscanf' and converting with 'cellstr', but that also doesn't format properly. I've tried just one "%s" but that also doesn't work.
Thank you.
4 Kommentare
Walter Roberson
am 3 Jan. 2019
If you are using Import Data, then a small number of releases ago the defaults on it changed so that now it imports text as String objects instead of cell array of character vectors. There is a button to change to use cell array of character vectors.
Eliseos Mucaki
am 4 Jan. 2019
Image Analyst
am 4 Jan. 2019
Bearbeitet: Image Analyst
am 4 Jan. 2019
Attach your file with the paper clip icon, and anything you know about its format, and we will try to read it in and then give you the code.
When you say
The program expects the input of a certain variable to be a 2-dimensional cell array of string vectors, i.e., a 40x10 cell array (each containing only one element of the array).
do you mean that the program expects the text data file to be of that format? Or is the file something else but needs to manipulate the file into that cell array for use later by the program?
Eliseos Mucaki
am 4 Jan. 2019
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Language Support finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!