Converting string to number
Show older comments
Hello All,
I need to convert a hug string data to numbers. The data is save in a variable based on the following command such that each row can lead to another huge matrix of data. So how can I convert this to numbers of class double?
for i = 1:1000
PowersScenario1(i+j1,:)={num2str(i) [csvread('ieee123_EXP_POWERS.CSV',1,1)]};
end
Thanks in advance.
Yara Hassan
6 Comments
DGM
on 16 Jun 2022
It's not clear what's actually in the output array. It's a cell array, where the first column contains char vectors converted from scalar integers. The second column contains a thousand copies of the same array of unknown size. I assume the array is ostensibly numeric.
If those array copies are already numeric, then the only non-numeric content in the cell array is in column 1, which was intentionally converted from numeric. The solution would be to simply not create the problem in the first place.
Since it's unclear what the geometry of the array copies in column 2 are (or expected to be), it's not really clear whether it's expected that the cell array can be converted into a numeric array. It's also not clear why you'd need a thousand copies of the same array. If this is just prototype code and those offsets change in the loop, then it's not even clear that the resultant arrays would have the same size.
Image Analyst
on 16 Jun 2022
Where is the hug string? i is a small number, and csvread returns an array of numbers, so where is the string?
Yara Hassan Moustafa
on 16 Jun 2022
Again, if the code is as shown and the data is being duplicated, why is any of this necessary?
Do you actually need 1000 (2000?) copies of the same data? If you don't, why not just open the .csv file in Excel and be done with it?
If the arrays are different, then how do you want to format the output?
Yara Hassan Moustafa
on 16 Jun 2022
Image Analyst
on 16 Jun 2022
Edited: Image Analyst
on 16 Jun 2022
Can you zip up two of the csv files and attach the file with the paperclip icon?
Do you have only one CSV file? This one: 'ieee123_EXP_POWERS.CSV'?
Or are there many of them and the filename actually changes in your for loop?
Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
