populating a cell using a loop
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
0 votes
Share a link to this question
2 Comments
Share a link to this comment
Share a link to this comment
Accepted Answer
0 votes
Share a link to this answer
- If you do not need those character columns then get textscan to ignore them with %*s in the format string. Then could trivially get textscan to collect all of the numeric data into one numeric array, using the CollectOutput option. Very simple, but you would lose some data.
- Use the CollectOutput option to collect the data into arrays of matching types: this would give you one 1x5 cell array C, containing an Nx14 numeric array, an Nx2 char cell array, an Nx29 numeric array, an Nx2 char cell array, and an Nx8 numeric array (or whatever sizes that format string gives you). I recommend this option.
- Use a table. These are a very convenient way for handling mixed data (e.g, numeric, char, categorical) and analyzing it. It has many powerful methods and operators for processing data by groups, and for statistical analyses.
- If you really want to get all of your data into one cell array (which will make any numeric processing slow, inefficient and complex), then you will need to post-process the data after it has been imported, something like this: detect numeric columns, convert numeric columns to cell array containing numeric scalars (e.g. num2cell), then concatenate all into one cell array. I strongly advise you to avoid doing this.
13 Comments
Share a link to this comment
Share a link to this comment
Share a link to this comment
Share a link to this comment
Share a link to this comment
Share a link to this comment
Share a link to this comment
Share a link to this comment

Share a link to this comment
Share a link to this comment
Share a link to this comment
Share a link to this comment
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)