Naming Variable from input arguments
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
My function takes two input arguments Dim,Snr I want to name my variable based on these two arguments in the following manner
Matrix_Dim{Snr}
for example if Dim=4, Snr=3 My cell variable should be named Matrix_4
Matrix_4{3}=somexyz where somexyz is the output which i want to store in Martix_4{3}
eval(['matrix_' num2str(DIM) '= somexyz']) will not create the cell array which i actually want to do.
how can i do that.
0 Commenti
Risposte (2)
Shashank Prasanna
il 30 Giu 2013
Try using {somexyz} instead of somexyz so that it is a cell.
0 Commenti
Walter Roberson
il 30 Giu 2013
2 Commenti
Walter Roberson
il 30 Giu 2013
Modificato: Image Analyst
il 30 Giu 2013
Don't do it.
Matrix{Dim}{Snr} = somexyz; %cell array
or
Matrix(Dim).Snr(Snr) = somexyz; %structure
Building variable names on the fly will always get you in trouble.
If you need the variable names to be separate for the purposes of save() then still do not construct the variable names on the fly. Instead,
matrices.(sprintf('matrix_%d', DIM)){Snr} = somexyz;
and then
save('FileName.mat', '-struct', 'matrices')
The post does address naming variables dynamically: it says DON'T, and shows the alternatives. And if you read it right through, it does show a way it can be done in the quite rare circumstance that it is needed.
Vedere anche
Categorie
Scopri di più su MRI in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!