Undefined Operator for type table

1 view (last 30 days)
Cordelia David
Cordelia David on 24 Apr 2019
Commented: Cordelia David on 3 May 2019
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 Comments
Peter Perkins
Peter Perkins on 3 May 2019
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.
Cordelia David
Cordelia David on 3 May 2019
I figured out that there was a word in one fo the structure values rather than a number. I merely replaced it with a number and it turned all of the cells back to a structure. Thank you!

Sign in to comment.

Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!