필터 지우기
필터 지우기

create output structure within a function

조회 수: 3 (최근 30일)
Mariska Kret
Mariska Kret 2011년 7월 1일
Hi,
I have problems getting the data output in a structure. I made a function in which I do several things. In the end, I want to have an output structure which contains different parts of the data.
this is how the script starts: function [output] = interpolate_csv (filename)
In the end I create the output like this: output = struct('pathstr','name','ext','baseline', 'postbaseline','postbaseline_baseline_corrected_0_500ms', 'postbaseline_baseline_corrected_500_1000ms', 'postbaseline_baseline_corrected_1000_1500ms', 'postbaseline_baseline_corrected_1500_2000ms', 'postbaseline_baseline_corrected_2000_2500ms', 'postbaseline_baseline_corrected_2500_3000ms', 'postbaseline_baseline_corrected_3000_3500ms', 'postbaseline_baseline_corrected_3500_4000ms')
All I get is this:
output =
''
What do I need to add to the script?
Thank you for your help.
best, Mariska

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 7월 1일
unless you mean this:
output = struct('pathstr','name','ext','baseline', 'postbaseline',{'postbaseline_baseline_corrected_0_500ms', 'postbaseline_baseline_corrected_500_1000ms', 'postbaseline_baseline_corrected_1000_1500ms', 'postbaseline_baseline_corrected_1500_2000ms', 'postbaseline_baseline_corrected_2000_2500ms', 'postbaseline_baseline_corrected_2500_3000ms', 'postbaseline_baseline_corrected_3000_3500ms', 'postbaseline_baseline_corrected_3500_4000ms'})
output =
1x8 struct array with fields:
pathstr
ext
postbaseline
>> output(1)
ans =
pathstr: 'name'
ext: 'baseline'
postbaseline: 'postbaseline_baseline_corrected_0_500ms'
  댓글 수: 5
Fangjun Jiang
Fangjun Jiang 2011년 7월 2일
output=struct('postbaseline',[postbaseline_baseline_corrected_0_500ms,postbaseline_baseline_corrected_500_1000ms]);
or
output=struct('postbaseline',[postbaseline_baseline_corrected_0_500ms;postbaseline_baseline_corrected_500_1000ms])
Mariska Kret
Mariska Kret 2011년 7월 6일
Thank you for the replies. I have it working now and also created a loop so that it saves data from multiple csv files.
data=struct('filename',filename,'baseline',baseline,'postbaseline',[postbaseline_baseline_corrected_0_500ms,postbaseline_baseline_corrected_500_1000ms...etc 3500_4000]);
I want to have an excel or csv file as output. This matrix should have the size of 10 columns (1 for filename, 1 for the baseline value, 8 different post-baseline values). Each unique .csv file should start on a new line.
xlswrite('filename',baseline,postbaseline);????

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 7월 1일
Do you mean
output=struct('pathstr',name,'ext',baseline,...)?
check the syntax of struct() again.
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 7월 1일
If I run your line directly, I got
??? Error using ==> struct
Field and value input arguments must come in pairs.
Check to make sure you always have the struct('param',value) with 'param' and value paired.
Jan
Jan 2011년 7월 1일
@Mariska: You did not get Jiangs point. It looks like you define the STRUCT with only the field names, but forget to insert the data also. But the syntax of STRUCT is: struct(name1, data1, name2, data2, ...).

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by