How to change string name?

4 visualizaciones (últimos 30 días)
Elzbieta Trynkiewicz
Elzbieta Trynkiewicz el 12 de En. de 2019
Comentada: Elzbieta Trynkiewicz el 13 de En. de 2019
Hey!
I have a function e.g. y=a*x.
How can I change later string name of y to y306 or sth like that?
  4 comentarios
Elzbieta Trynkiewicz
Elzbieta Trynkiewicz el 13 de En. de 2019
Thank you for your comment but could you explain me more or help with following problem?
I created this question since I have such kind of problem: I tried to load multiple data which was previously saved like a 'y'; but all of these, despite the different external filename, they have the same name of "internal" variable and they are overwriting.
Stephen23
Stephen23 el 13 de En. de 2019
"I tried to load multiple data which was previously saved like a 'y'; but all of these, despite the different external filename, they have the same name of "internal" variable and they are overwriting."
Aaah, that is an entirely different question to what you asked about: http://xyproblem.info/

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 13 de En. de 2019
Editada: Stephen23 el 13 de En. de 2019
The solution is to simply use indexing. For example, you could put all of your imported data into one cell array. You did not give much information in your question (e.g. the file format, what function you are using to import the data, the data class, whether you generate the name with sprintf or use dir to obtain the names of existing files, etc), so I will show an example that imports data from .mat files using load:
S = dir('*.mat');
N = numel(S);
C = cell(1,N); % preallocate.
for k = 1:N
C{k} = load(S(k).name);
end
A = [C{:}] % optional, create non-scalar structure.
Then all of the imported data will be available in the cell array C or (even better) the non-scalar structure A:
If the loaded .mat files only contain one (or a few) variables that you need, you can easily access them inside the loop and put that data into on (or a few) array, e.g.:
S = dir('*.mat');
N = numel(S);
C = cell(1,N); % preallocate.
for k = 1:N
T = load(S(k).name);
C{k} = T.y;
end
Feel free to adapt the class and size to suit your data: depending on your data you could import into a numeric/char/string array, with columns/rows to suit number of variables, etc..
You should read this too:
  1 comentario
Elzbieta Trynkiewicz
Elzbieta Trynkiewicz el 13 de En. de 2019
Thank you very much for your help!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures 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