converting structure array to xls file

Dear all,
I have a huge structure array of patient datasets that looks like this:
(patient_name).(year_of_visit).(type_of_visit).(score)
I need to convert this structure array to excel or csv file in a matter I'd be able to use it in Excel, SPSS, etc for further analysis. However, I'm not able to export this easily. Any input is much appreciated!

댓글 수: 2

Walter Roberson
Walter Roberson 2012년 6월 25일
I take it the goal would be to output the relevant structure member names, and the content of the score field, as rows ?
Arman
Arman 2012년 6월 26일
That's correct. Your script almost do the trick. Thanks

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

 채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 25일

1 개 추천

This is probably most easily done through recursion and basic file I/O
function dump_patient_record( fields_above_here, current_level, fid )
if ~isstruct(current_level)
fprintf(fid, '%s,', fields_above_here{:});
fprintf(fid, '%f\n', current_level ); %assuming it is a scalar for simplicity
else
thesefields = fieldnames(current_level);
for K = 1 : length(thesefields)
thisfield = thesefields{K};
dump_patient_record( [fields_above_here {thisfield}], current_level.(thisfield), fid );
end
end

추가 답변 (1개)

Tom
Tom 2012년 6월 25일

0 개 추천

The struct2cell function is probably what you need, though you'll have to dig through a bit as it only goes to the first level of the structure

카테고리

도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by