create output structure within a function

3 次查看(过去 30 天)
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