String to double conversion misunderstanding
Ältere Kommentare anzeigen
I'm modifying on table imported from csv, the fields (rep.ACVoltageR), of course, are char. I try to modify the fields to double, using
tensione = str2double(rep.ACVoltageR);
but tensione is still as a char and not a double.
Were is may mistake?
>> class ACVoltageR
ans =
'char'
>> class tensione
ans =
'char'
Thanks, Fabrizio
3 Kommentare
dpb
am 15 Feb. 2026 um 19:01
How are you getting rep.ACVoltageR? If, as is implied by the reference to csv it's from a .csv file, it would be simpler to read in as numeric directly unless it is mal-formatted.
We don't have sufficient information to answer; we need the actual data how how obtained.
"I'm modifying on table imported from csv, the fields (rep.ACVoltageR), of course, are char."
Why "of course" ?
Most likely it would be much simpler and/or robust to import that numeric data correctly as numeric data. This is the approach that I strongly recommend. If you upload your data by clicking the paperclip button then we can help you with that.
"Were is may mistake?"
Possibly you tried allocating the numeric data to a table variable/column which has class character. But as you have not shown us your actual code, we will just have to guess.
fabrizio restori
am 15 Feb. 2026 um 21:42
Akzeptierte Antwort
Weitere Antworten (1)
The mistake is that you're using command form for calling the class function, not function form. These:
class ACVoltageR
class tensione
are equivalent to:
class('ACVoltageR')
class('tensione')
Also note that at this point in the execution my answer, there are no variables named ACVoltageR and tensione in the workspace!
whos ACVoltageR tensione ans % only ans is listed
If you want to ask for the class of the variable named tensione, use function form passing in the variable not its name.
tensione = str2double('42');
class(tensione)
whos ACVoltageR tensione ans % ans and tensione are listed, ACVoltageR still doesn't exist
Kategorien
Mehr zu Image Arithmetic 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!