Undefined Operator for type table

조회 수: 1 (최근 30일)
Cordelia David
Cordelia David 2019년 4월 24일
댓글: Cordelia David 2019년 5월 3일
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
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.
Cordelia David
Cordelia David 2019년 5월 3일
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!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by