필터 지우기
필터 지우기

Function not returning the desired structure

조회 수: 4 (최근 30일)
David Meixell
David Meixell 2020년 10월 30일
댓글: David Meixell 2020년 10월 30일
When testing my function to build a structure based on a .dat file, the output shows the desired struct 'kepler' but seems to overwrite with the same size struct 'ans.' Why is it doing this, and how can I fix it?
function kepler = loadkepler(filename)
data = load(filename);
kepler.svid = data(1:end,1);
kepler.meananomaly = data(1:end,2);
kepler.omega = data(1:end,3);
kepler.radius = data(1:end,4);
kepler.inclination = data(1:end,5);
kepler.reftime = data(1:end,6);
end
When I test it with just the 'svid' field, this is the output:
>> loadkepler
kepler =
struct with fields:
svid: [24×1 double]
ans =
struct with fields:
svid: [24×1 double]
Attempts to build a bar graph only work if I use 'ans.svid' instead of 'kepler.svid'

채택된 답변

Stephan
Stephan 2020년 10월 30일
편집: Stephan 2020년 10월 30일
You dont assign the output of the function to a variable - use:
kepler = loadkepler...
  댓글 수: 1
David Meixell
David Meixell 2020년 10월 30일
Well, that worked!
I thought I wouldn't have to do that, as the struct 'kepler' is created when I assign each field. Does MATLAB not recognize the struct as a valid output of the function? I'm confused as to what's going on behind the scenes.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by