Zip across variables in workspace in a for loop
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am having a bit of trouble (I am hoping this is actually a really simple fix to something I am doing wrong) creating a for loop that accesses variables I have in my workspace. I have three variables in my workspace (violin, cello, piano) all of the same size 14*128*657. The following code to reshape the variables works, but the problem is when I try and turn it into a for loop.
S = size(violin); % check to make sure all datasets are the same size
violin = reshape(violin,[S(2)*S(3), S(1)]);
violin = double(violin);
piano = reshape(piano,[S(2)*S(3), S(1)]);
piano = double(piano);
cello = reshape(cello,[S(2)*S(3), S(1)]);
cello = double(cello);
for i=['violin', 'cello', piano']
i = reshape(i,[S(2)*S(3), S(1)]);
i = double(i);
end
I have tried several things (including using curly brackets, etc.) but get the error: Error using reshape To RESHAPE the number of elements must not change.
Thanks for all the help in advance!
Anna
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!