Why did I get duplicate variables in my workspace after changing their names?
(I did solve this problem but I haven’t been able to repeat it. I hope it’s okay to ask here anyway because I am curious if anyone has an explanation. I will describe below what solved it and how I have tried to repeat it. Couldn’t find any threads describing this anywhere.)
I had a few variables in my script with names starting with capital letters that I wanted to change to lowercase first letters. For example I wanted to change "Flux_th" to "flux_th". See code example below with only the relevant lines from my script.
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
Flux_th = 42078172084928.6; % [neutrons/cm2/s]
I used the shift+enter function in matlab to change "Flux_th" to "flux_th" (same with the other variables).
I cleared my workspace, I ran the script (like below) and got BOTH "Flux_th" and "flux_th" in my workspace (they have the same value).
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
I tried changing back to capital letters on "Flux_th" and doing the same thing again but it still gave me duplicates.
I am pretty sure that I tried manually deleting the duplicates with capital letters in the workspace and then running the script, but that also gave me duplicates.
It happened again even after restarting matlab.
What DID actually solve the problem is the following sequence:
I cleared the workspace, then I ran this separate script that creates and saves the .mat files, that script looks like this:
%% Global nuclear data
%data for reactions
dataNucGlobal_reac = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["barn";"isotopefrac";"reference"]);
dataNucGlobal_reac(‘O16 (n,p) N16: s-f’, 🙂 = {2.026e-5, 99.76, "ENDL"};
save(‘dataNucGlobal_reac’)
%data for nuclides
dataNucGlobal_nuc = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["halflife_s"; "decayconst"; "reference"]);
dataNucGlobal_nuc(‘N16’, 🙂 = {7.12, log(2)/7.12, "?"};
save(‘dataNucGlobal_nuc’)
Then I ran my original script without the load lines like this:
% load(‘dataNucGlobal_nuc.mat’)
% load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
This time I did not get any duplicates, so I cleared my workspace again and reinserted the load lines and finally ran the script like this:
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
Now everything is working and I can’t reproduce what happened by changing variable names from capital to lowercase letters.
I am super confused because as you can see, the .mat-files DO NOT contain any of the variables that became duplicates, so it doesn’t make any sense that this would help. I have no idea what happened so that is why I am asking here.(I did solve this problem but I haven’t been able to repeat it. I hope it’s okay to ask here anyway because I am curious if anyone has an explanation. I will describe below what solved it and how I have tried to repeat it. Couldn’t find any threads describing this anywhere.)
I had a few variables in my script with names starting with capital letters that I wanted to change to lowercase first letters. For example I wanted to change "Flux_th" to "flux_th". See code example below with only the relevant lines from my script.
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
Flux_th = 42078172084928.6; % [neutrons/cm2/s]
I used the shift+enter function in matlab to change "Flux_th" to "flux_th" (same with the other variables).
I cleared my workspace, I ran the script (like below) and got BOTH "Flux_th" and "flux_th" in my workspace (they have the same value).
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
I tried changing back to capital letters on "Flux_th" and doing the same thing again but it still gave me duplicates.
I am pretty sure that I tried manually deleting the duplicates with capital letters in the workspace and then running the script, but that also gave me duplicates.
It happened again even after restarting matlab.
What DID actually solve the problem is the following sequence:
I cleared the workspace, then I ran this separate script that creates and saves the .mat files, that script looks like this:
%% Global nuclear data
%data for reactions
dataNucGlobal_reac = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["barn";"isotopefrac";"reference"]);
dataNucGlobal_reac(‘O16 (n,p) N16: s-f’, 🙂 = {2.026e-5, 99.76, "ENDL"};
save(‘dataNucGlobal_reac’)
%data for nuclides
dataNucGlobal_nuc = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["halflife_s"; "decayconst"; "reference"]);
dataNucGlobal_nuc(‘N16’, 🙂 = {7.12, log(2)/7.12, "?"};
save(‘dataNucGlobal_nuc’)
Then I ran my original script without the load lines like this:
% load(‘dataNucGlobal_nuc.mat’)
% load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
This time I did not get any duplicates, so I cleared my workspace again and reinserted the load lines and finally ran the script like this:
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
Now everything is working and I can’t reproduce what happened by changing variable names from capital to lowercase letters.
I am super confused because as you can see, the .mat-files DO NOT contain any of the variables that became duplicates, so it doesn’t make any sense that this would help. I have no idea what happened so that is why I am asking here. (I did solve this problem but I haven’t been able to repeat it. I hope it’s okay to ask here anyway because I am curious if anyone has an explanation. I will describe below what solved it and how I have tried to repeat it. Couldn’t find any threads describing this anywhere.)
I had a few variables in my script with names starting with capital letters that I wanted to change to lowercase first letters. For example I wanted to change "Flux_th" to "flux_th". See code example below with only the relevant lines from my script.
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
Flux_th = 42078172084928.6; % [neutrons/cm2/s]
I used the shift+enter function in matlab to change "Flux_th" to "flux_th" (same with the other variables).
I cleared my workspace, I ran the script (like below) and got BOTH "Flux_th" and "flux_th" in my workspace (they have the same value).
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
I tried changing back to capital letters on "Flux_th" and doing the same thing again but it still gave me duplicates.
I am pretty sure that I tried manually deleting the duplicates with capital letters in the workspace and then running the script, but that also gave me duplicates.
It happened again even after restarting matlab.
What DID actually solve the problem is the following sequence:
I cleared the workspace, then I ran this separate script that creates and saves the .mat files, that script looks like this:
%% Global nuclear data
%data for reactions
dataNucGlobal_reac = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["barn";"isotopefrac";"reference"]);
dataNucGlobal_reac(‘O16 (n,p) N16: s-f’, 🙂 = {2.026e-5, 99.76, "ENDL"};
save(‘dataNucGlobal_reac’)
%data for nuclides
dataNucGlobal_nuc = table(‘Size’,[0,3], ‘VariableTypes’,["double", "double", "string"],’VariableNames’,["halflife_s"; "decayconst"; "reference"]);
dataNucGlobal_nuc(‘N16’, 🙂 = {7.12, log(2)/7.12, "?"};
save(‘dataNucGlobal_nuc’)
Then I ran my original script without the load lines like this:
% load(‘dataNucGlobal_nuc.mat’)
% load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
This time I did not get any duplicates, so I cleared my workspace again and reinserted the load lines and finally ran the script like this:
load(‘dataNucGlobal_nuc.mat’)
load(‘dataNucGlobal_reac.mat’)
flux_th = 42078172084928.6; % [neutrons/cm2/s]
Now everything is working and I can’t reproduce what happened by changing variable names from capital to lowercase letters.
I am super confused because as you can see, the .mat-files DO NOT contain any of the variables that became duplicates, so it doesn’t make any sense that this would help. I have no idea what happened so that is why I am asking here. variable-names, duplicates MATLAB Answers — New Questions
​