create output structure within a function
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Fangjun Jiang
il 1 Lug 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 Commenti
Fangjun Jiang
il 2 Lug 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])
Più risposte (1)
Fangjun Jiang
il 1 Lug 2011
Do you mean
output=struct('pathstr',name,'ext',baseline,...)?
check the syntax of struct() again.
3 Commenti
Fangjun Jiang
il 1 Lug 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
il 1 Lug 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, ...).
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!