create a ndgrid given based on string variable input
Mostrar comentarios más antiguos
Hi there. Let's start say I'm given a 1x2 cell list..
t={'x1','x2'} % and
T = upper(t) % upper case of t
After this I've defined x1 and x2 with the eval function
eval([t{1} '= 1:1:10;'])
eval([t{2} '= 1:1:10;'])
How do I create a meshgrid [X1,X2]=meshgrid(x1,x2) from the cell 'T'? If 't' can be any length of 1:3 and could be any combination of x1, x2 and x3 for example
t={'x2','x3'} % x1 is a constant want -> [X2,X3]=meshgrid(x2,x3)
t={'x1','x3'} % x2 is a constant want -> [X1,X3]=meshgrid(x1,x3)
t={'x1','x2','x3'} % want to create 3D mesh (no constants) -> [X1,X2,X3]=meshgrid(x1,x2,x3)
t={'x3'} % no mesh just X3=x3 (x1 and x2 are constants)
I hope this makes sense. Just to recap my cell vector 't' is generated from my previous code and gives which what x# is required and sets up the meshing with eval.
I'll explain further if required thanks,
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!