How do I use sprintf with two variables with different sizes?
古いコメントを表示
Hello!
I am analysing MEG data and have 20 participants with 3 blocks (called '00', '10' and '23') each, so 20x3 datasets. I want to append all these datasets with a function.
In the function, I have to manually spell out ALL the datasets that I want to append. For example:
[appendeddata] = ft_appenddata(cfg, s(1).rawdata.data00, s(1).rawdata.data10, s(1).rawdata.data23, s(2).rawdata.data00,... %and so forth
So I would have to spell out all 60 combinations, so s(1:20) and block(00,10,23). I tried to get around this by using sprinft like this:
block=["00" "10" "23"];
Subj=strings(1,20);
Subj(1:20)=1:20;
sprintf('s(%s).rawdata.data%s,',Subj,block)
But this leads to this:
ans = 's(1).rawdata.data2,s(3).rawdata.data4,s(5).rawdata.data6,s(7).rawdata.data8,s(9).rawdata.data10,s(11).rawdata.data12,s(13).rawdata.data14,s(15).rawdata.data16,s(17).rawdata.data18,s(19).rawdata.data20,s(00).rawdata.data10,s(23).rawdata.data'
How can I tell sprintf to assign the values of the first variable "Subj" to the first instance of %s, and the values of the second variable "block" to the second instance? Is that possible at all?
Thanks in advance for any answers!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!