How to extract a string from a list and use it with dot notation
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a list of strings, lets say
stringListUpper = ["ABC","DEF","GHI"].
I would like to extract the strings from the list and use them in dot notation. For example, I would like to assign a value to ABC.a and another value to ABC.b.
I tried something like this:
stringListUpper = ["ABC","DEF","GHI"].
stringListLower = ["abc","def","ghi"];
for i = 1:3
for j = 1:3
stringListUpper(i).stringListLower(j) = 1;
end
end
Is what I'm wanting to do possible and if so, how?
Respuestas (1)
Walter Roberson
el 11 de Feb. de 2025
stringListUpper = ["ABC","DEF","GHI"];
stringListLower = ["abc","def","ghi"];
for i = 1:3
for j = 1:3
AssignTo(stringListUpper(i) + "." + stringListLower(j), i*10+j);
end
end
whos
fieldnames(ABC)
function AssignTo(name, value)
tname = tempname() + ".m";
fid = fopen(tname, 'w');
fprintf(fid, "%s = %.999g;\n", name, value);
fclose(fid);
[filedir, filename, filext] = fileparts(tname);
addpath(filedir);
evalin('caller', filename)
rmpath(filedir)
delete(tname)
end
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!