How to read comma separated input data containing values & stings which also has ',' & ';' used for separation?
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.
Show older comments
How to read comma separated input data containing values & stings which also has ',' & ';' used for separation?
Example:
#SATVISA,COM1_30,0,88.5;COARSESTEERING,1833,167463.000,00400000,0947,12996;TRUE,TRUE,30,16,0,0,79.0,111.5
Accepted Answer
dpb
on 11 Mar 2015
doc textscan % NB: 'delimiter' Name-Value Pair with example for multiple delimiter characters.
6 Comments
Thank you so much.
I got the answer in a cell format which I am unable to use as input. I got answer as C_text cell and C_text{1,1} has the array I need.
I am using d = cell2mat(c) to convert it into one array but I am getting error as 'Cannot support cell arrays containing cell arrays or objects.'
Is there any other way I can convert this output in readable format for my program?
Shree
on 11 Mar 2015
I got it when I saved the C_text{1,1} as a separate variable.
Thank you so much.
Well, your input line as mixed text and numeric fields so it can't be anything but either a cell array or recast to a structure or somesuch.
You don't say what specific format you do need so don't know what to say for any explicit rearrangement that might be more suitable. If there's still an issue, post back the details of what your requirements are and we'll see...
When I decoded the data from input file, all output data array came in cell format. Example: {'38.95','-95.25';'38.94','-95.24';'38.93','-95.23';}
With this data I am unable to plot any graph or do any operations so I tried to convert it into normal array form by using STR2DOUBLE, str2num, cell2mat but I am not able to get it right.
Because this is in cell form I had to use 'isequal' function instead of '==' for normal operations.
I need this data in a normal matrix form in order to do the operations like plot and normal mathematical operations.
Is there any way I can do that?
dpb
on 12 Mar 2015
Use the 'collectoutput',1 name-value pair to put the string and numeric data into separate (still cell) arrays. Again I repeat, you can not put the two types of data in the same array; just not possible.
You can then use cell2mat on the numeric array to get a regular array of numeric values; again you leave out pertinent details of what data are to go together for plotting, etc., so that's a detail to deal with.
Or, of course, to use the cell array as is, you "use the curlies" the {} brackets to dereference the content of a cell. Read the doc on cell arrays for the details there.
Again, specific examples of what you want to do help more than just generalizations.
Shree
on 12 Mar 2015
I will try this approach. Thank you so much!
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
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)