Borrar filtros
Borrar filtros

Zip across variables in workspace in a for loop

3 visualizaciones (últimos 30 días)
Anna Kasdan
Anna Kasdan el 2 de Abr. de 2018
Editada: Matt J el 3 de Abr. de 2018
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

Respuesta aceptada

Matt J
Matt J el 2 de Abr. de 2018
Editada: Matt J el 3 de Abr. de 2018
C=struct('violin',violin,'cello',cello,'piano',piano};
C=structfun( @(i) double( reshape(i,[S(2)*S(3), S(1)]) ) , C ,'uni', 0)

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by