trouble turning a 1x1 cell into a double

I'm trying to read a series of files into an array and ensure the data from Current_Coil_1_A is read in and converted to a double. Here's my csv file format:
"Coil Flux-Linkage: Wb <Time, s:0, Step: 1>"
"","Value"
"Current_Coil_1_B","0.0400143721601"
"Current_Coil_1_A","0.0400142095048"
I want "0.0400142095048" turned into a double of precision 3 or so. So I cycle through the number of cases:
for n = 1:cases
currentCSVFile = fopen('filename' num2str(n) '.csv');
fgetl(currentCSVFile) %reads line but does nothing with it
fgetl(currentCSVFile)
fgetl(currentCSVFile)
temp = textscan(currentCSVFile, '%*q%q%*q', 'Delimiter',',');
DataArray(1,n) = str2double(temp);
end
DataArray will then appear as NaN even though I think temp should be a valid argument. Any help would be appreciated.

 Accepted Answer

Your ‘temp’ variable is a cell array. I have no idea what it contains, so a guess here.
Try this:
DataArray(1,n) = str2double(temp{:});
Another option is to use the cell2mat function.

2 Comments

Sorry it took me so long to accept. Great answer!
No worries! The longest documented time between my Answer and the poster’s Accept was 198 days, and I know that only because the poster thanked me.
Thank you!

Sign in to comment.

More Answers (0)

Categories

Products

Tags

Asked:

Liz
on 28 Apr 2016

Commented:

on 12 May 2016

Community Treasure Hunt

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

Start Hunting!