참고 : 'eval'이없는 솔루션을 가리킬 수 있다면 좋을 것입니다. 하지 않으면, 음, 첫 번째 행의 문자열과 두 번째 행의 행렬에있는 세포 (Var_s
)이 너무 :-) 나는 감사 할 것이다 :이름이있는 Matlab 셀
clc
clearvars
fclose all
L=[11 22 33 44];
M=[1 2 3];
N=[101 102 103 104 105, 95 96 97 98 99];
Var_s=cell(2,3);
Var_s(1,1:3)={'Rn', 'LE', 'O'}; %// The strings are all different and were not created in a loop.
Var_s(2,1:3)={L, M, N}; %// No correlation is possible.
%//Than I delete all variables because I can work with the cell (Var_s{2,:})
%//to execute some computations
clearvars L M N
%//Now I want to save the values which are stored inside of the cells in the
%//second line of Var_s, Var_s{2,:}, associating to them the names in the first
%//row of the Var_s, Var_s{1,:}, in a .mat file
%//But let's imagine that instead of having size(Var_s{2,:})=3 I would have
%//something like 1000 (but lets keep it simple for now having just 3).
%//Consequently I want to use a 'for' to do this work!
%//And it is at this point that the issue appears. How can I use the strings
%//inside Var_s{1,:} to create variables and store them in the .mat file with
%//the values in the cells of Var_s{2,:} associated to them?
filename='Clima';
a=0;
save(filename,'a'); %//Creats the file with a variable a=0
for i=1:length(Var_s(2,:))
genvarname(Var_s{1,i})=Var_s{2,i}; %//The idea is to create a variable using a stringn and associate the values
save(filename,char(Var_s{1,i}),'-append'); %//The idea is to add the created variable that has the same name in Var_s{1,i}
end
clearvars
%//After all this I could access the variables that are stored in 'Clima.mat'
%//by their name such as
load('Clima.mat')
Rn
LE
O
을 그리고 결과는
을해야합니다Rn = 11 22 33 44
LE = 1 2 3
N = 101 102 103 104 105
코드 형식을 남겨두고 이후 질문을 위해 코드 형식을 벗어난 텍스트 설명을 입력하십시오 (해당 질문을 적절히 편집하십시오). – Nras