Undefined Operator for type table
조회 수: 3 (최근 30일)
이전 댓글 표시
I have written a code to read from a csv file, write ariables to variable names, and use those variables in various equations. I have most of the code done, but my equations are giving me an error. I have a csv file that looks like this:
Orbital Input Variables Values Units
Altitude 841 km
OrbitalType 0
RadiusEarth 6378100 m
And I have a readcsv file that looks like:
Orbits = readtable('OrbitalInputs.csv','HeaderLines',0,'ReadVariableNames',true);
mask = ~cellfun(@isempty,Orbits.(1));
OrbitalInputs = cell2struct(num2cell(Orbits{mask,2}),Orbits{mask,1});
OrbitalInputs.Remark = 'These are my imported Orbital variables';
As well as a function to set these values equal to the variables that looks like:
function OrbitalInputs = SetOrbitalInputs()
tOrbit = readtable('orbitalInputs.csv','readRowNames',1);%Creates a table of values from the imported csv file
OrbitalInputs.Altitudekm = tOrbit{'Altitude','Values'};
OrbitalInputs.OrbitalType_ZeroForCircular = tOrbit{'OrbitalType','Values'};
end
And another function that looks like this:
function OrbitalCalc = OrbitalValues(OrbitalInputs)
tOrbit = readtable('orbitalInputs.csv','readRowNames',1);%Creates a table of values from the imported csv file
% Altitudes in different Units
OrbitalCalc.Altitude.Miles = 0.621371192 .* OrbitalInputs.Altitudekm;
OrbitalCalc.Altitude.NautMile = 0.539956803 * OrbitalInputs.Altitudekm;
OrbitalCalc.Altitude.Meters = 1000 * OrbitalInputs.Altitudekm;
end
But I keep getting an error that says
"Undefined operator '.*' for input arguments of type 'cell'.
Error in OrbitalValues (line 11)
OrbitalCalc.Altitude.Miles = 0.621371192 .* OrbitalInputs.Altitudekm;"
What am I doing wrong?
댓글 수: 3
Peter Perkins
2019년 5월 3일
I think you want to step through your code in the debugger and see why you are ending up with a cell array for something that I think you expect to be numeric. I expect it has to do with this
'HeaderLines',0
which causes readtable to treat all of your data as text.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!