<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hey Jan-Mathijs,</p>
<p><br>
</p>
<p>thanks a lot! Good to know that I need cell instead of structures for sthg. like that. Maybe I will change my bookkeeping in the future ;)</p>
<p><br>
</p>
<p>Kind regards,</p>
<p>Erika<br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> fieldtrip <fieldtrip-bounces@science.ru.nl> im Auftrag von Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen@donders.ru.nl><br>
<b>Gesendet:</b> Dienstag, 16. Juli 2019 16:14:29<br>
<b>An:</b> FieldTrip discussion list<br>
<b>Betreff:</b> Re: [FieldTrip] Several variables as input into function without writing them manually?</font>
<div> </div>
</div>
<div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">Hi Erika,</span>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class="">
</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">You could do the following:</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class="">
</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">tmp = cell(1,numel(s));</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">for k = 1:numel(s)</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">  tmp{k} = s(k).rawdata.data00;</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">end</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">appendeddata = ft_appenddata(cfg, tmp{:});</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class="">
</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">In short, a varargin type of argument needs to be represented as a (curly bracket expanded) cell-array. Struct-arrays (as in your case) may be easy to work with in other situations (e.g.
 when you quickly want to concatenate fields from different structures) , but indeed not so much in a situation where you want to flexibly input multiple arguments into a function. Your use of nested struct arrays is perhaps handy in terms of bookkeeping, but
 makes concise coding somewhat complicated (not that it’s wrong, but I just want to have it mentioned :) ).</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class="">
</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">I hope this helps,</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class="">
</div>
<div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Jan-Mathijs</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 16 Jul 2019, at 12:06, Erika Puiutta <<a href="mailto:erika.puiutta@uni-oldenburg.de" class="">erika.puiutta@uni-oldenburg.de</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper">Hello!</span></span></div>
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper"><br class="">
</span></span></div>
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper">I am analysing MEG data and have 20 participants, so 20 datasets. I want to append all these with ft_appenddata.</span></span></div>
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper">Is there a way to plug in all the variable names without having to manually spell out all of them?<span class="Apple-converted-space"> </span><br class="">
</span></span></div>
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper">For example:</span></span></div>
<div class="contiguous CodeBlock">
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">[appendeddata] = ft_appenddata(cfg, s(1).rawdata.data00,<span class="textBox"><span class="textWrapper">s(2).rawdata.data00</span></span>,<span class="Apple-converted-space"> </span><span class="textBox"><span class="textWrapper">s(3).rawdata.data00</span></span>,</span><span class="Keyword textWrapper">...</span><span class="Comment textWrapper"><span class="Apple-converted-space"> </span>and
 so forth</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="Comment textWrapper"><br class="">
</span></span></div>
</div>
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper">So I would have to spell out all 20 names which is quite cumbersome. I tried to get around this by using sprinft like this:</span></span></div>
<div class="paragraphNode wrappable"><span class="textBox"><span class="textWrapper"><br class="">
</span></span></div>
<div class="contiguous CodeBlock">
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">
<div class="">k=strings(1,20);<br class="">
k(1:20)=1:20;<br class="">
cfg=[];<br class="">
[appendeddata] = ft_appenddata(cfg,sprintf('s(%s).rawdata.data00,',k));<br class="">
<br class="">
</div>
</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"><br class="">
But if I do this, I get these errors:</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">
<div class="">Error using ft_checkdata (line 529)<br class="">
This function requires 'raw' or 'raw+comp' data as input, see ft_datatype_raw.<br class="">
<br class="">
Error in ft_appenddata (line 102)<br class="">
  varargin{i} = ft_checkdata(varargin{i}, 'datatype', {'raw', 'raw+comp'}, 'feedback', 'no', 'hassampleinfo', cfg.keepsampleinfo);</div>
<br class="">
</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">So I guess using sprintf doesn't work. Is there another way to put in several variables into ft_appenddata (or any other fieldtrip function) without
 having to write them down myself?</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"><br class="">
</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">Thanks for your answers in advance!</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper"><br class="">
</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">Kind regards</span></span></div>
<div class="lineNode mwRichTextComponentLine plainTextFixedSize"><span class="textBox"><span class="textWrapper">Erika<br class="">
</span></span></div>
</div>
</div>
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">fieldtrip
 mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://doi.org/10.1371/journal.pcbi.1002202" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://doi.org/10.1371/journal.pcbi.1002202</a></div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>