create output structure within a function

2 Ansichten (letzte 30 Tage)
Mariska Kret
Mariska Kret am 1 Jul. 2011
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

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 1 Jul. 2011
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 Kommentare
Fangjun Jiang
Fangjun Jiang am 2 Jul. 2011
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 am 6 Jul. 2011
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);????

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 1 Jul. 2011
Do you mean
output=struct('pathstr',name,'ext',baseline,...)?
check the syntax of struct() again.
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 1 Jul. 2011
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 am 1 Jul. 2011
@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, ...).

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by