MATLAB

2014-05-14 1 views
0

내 구조는 세 개의 필드가 있습니다 마지막으로MATLAB

function design = loadSelfSimp(design,values) 
design.newField = values(1); 

그리고의 : 새 필드를 추가하여

>> design 

design = 

       E: [1x101 double] 
       F: [1x21 double] 
     bandsImg: [] 

지금, 나는 함수에서 그 구조를 수정을 내 주요 코드 :

:

design = loadSelfSimp(design, somevalues) 

MATLAB에 대한 불평

Subscripted assignment between dissimilar structures. 

Error in selfSimpPoor (line 101) 
     design(i) = loadSelfSimp(design(i),selfSimp_out); 

무엇이 문제입니까? 그것을 쉽게 고치는 방법?

코드 :

function [design,conv] = selfSimp(design,question) 

if nargin == 1 
    question = 1; 
end 
numDes = length(design); 

for i = 1:numDes 

    well = design(i).well; 
    barr = design(i).barr; 
    dopeWell = design(i).dopeWell; 
    dopeBarr = design(i).dopeBarr; 
    barrX = design(i).barrX; 
    elemDens = design(i).elemDens; 
    numPer = design(i).numPer; 
    iterFac = design(i).iterFac; 
    posMeth = design(i).posMeth; 
    if isfield(design(i),'bandSwitch') 
     bandSwitch = design(i).bandSwitch; 
     design(i).wvFunslh = []; 
     design(i).Elh = []; 
     design(i).wvFunshh = []; 
     design(i).Ehh = []; 
    else 
     bandSwitch = 1; 
    end 
    elecTemp = design(i).elecTemp; 

    numWell = length(well); 

    %check if there is any value in minSplitField 
    if isfield(design(i),'minSplitField') && (isempty(design(i).minSplitField) == 0) 
     minSplitField = design(i).minSplitField; 
    else 
     F = design(i).F; 
     minSplitField = F(ceil(numF/2)); 
    end 

    %%%%% do some tests before starting 
    %%% Test to see if F, well and barr are row vectors 


    sze = size(well); 
    if sze(1)~=1 
     disp('  WARNING: well is either not one dimentional or is a column vector') 
    end 
    sze = size(barr); 
    if sze(1)~=1 
     disp('  WARNING: barr is either not one dimentional or is a column vector') 
    end 
    clear sze 

    disp(minSplitField); 

    %save the values found for read in by 'qclsolve' 
    fid = fopen('../../bin/qclsolve_in.dat','w'); 
    fprintf(fid,'#\n#\n# Number of wells:\n'); 
    fprintf(fid,'%-2.0f',numWell); 
    fprintf(fid,'\n#\n#\n#\n# Widths of wells:\n'); 
    fprintf(fid,'%-9.4f',well); 
    fprintf(fid,'\n#\n#\n#\n# Widths of barriers\n'); 
    fprintf(fid,'%-9.4f',barr); 
    fprintf(fid,'\n#\n#\n#\n# Doping in wells\n'); 
    fprintf(fid,'%-10.2e',dopeWell); 
    fprintf(fid,'\n#\n#\n#\n# Doping barriers\n'); 
    fprintf(fid,'%-10.2e',dopeBarr); 
    fprintf(fid,'\n#\n# Aluminum barrier fraction\n'); 
    fprintf(fid,'%-6.4f',barrX); 
    fprintf(fid,'\n#\n# Element density (for grid/mesh)\n'); 
    fprintf(fid,'%-4.2f',elemDens); 
    fprintf(fid,'\n#\n# minSplitField - field at which minimum injector-upper occours\n'); 
    fprintf(fid,'%-4.2f',minSplitField); 
    fprintf(fid,'\n#\n# number of period repeats\n'); 
    fprintf(fid,'%-2.0f',numPer); 
    fprintf(fid,'\n#\n# starting fraction of electrons to use in self-consistant\n'); 
    fprintf(fid,'%-4.2f',iterFac); 
    fprintf(fid,'\n#\n# method of finding electron positions (1 or 2, 1 is best)\n'); 
    fprintf(fid,'%-2.0f',posMeth); 
    fprintf(fid,'\n#\n# Which band we are soling in (1=Conduction, 2=Valence)\n'); 
    fprintf(fid,'%-2.0f',bandSwitch); 
    fprintf(fid,'\n#\n# If the solution is to self-consistant then =1, else 0 \n'); 
    fprintf(fid,'%-2.0f',1); 
    fprintf(fid,'\n#\n# Electron temperature in Kelvin\n'); 
    fprintf(fid,'%-6.2f',elecTemp); 
    fclose(fid); 

    %call the solver to print the band structure at the minimum splitting field 
    if isunix 
     unix('././bin/qclsolve'); 
    else 
     dos('..\..\bin\qclsolve.exe'); 
    end 

    selfSimp_out = load('../../bin/states_out.dat'); 

    conv(i) = selfSimp_out(1,end); 

    %what to do depends on if it converged 
    if conv(i) || (question==2) 
     design(i) = loadSelfSimp(design(i),selfSimp_out); 
% design_a = loadSelfSimp(design(i),selfSimp_out); 
    elseif question == 1 
     cont = input('Did not converge, load anyway? (y/n)','s'); 
     if cont == 'y' 
      design(i) = loadSelfSimp(design(i),selfSimp_out); 
     end 
    end 

end 

function design = loadSelfSimp(design,selfSimp_out) 

lower = design.lowInjUp(1); 
injector = design.lowInjUp(2); 
upper = design.lowInjUp(3); 
upper2 = design.lowInjUp(4); 
extractor = design.lowInjUp(5); 
LO = design.lowInjUp(6); % extractor1 
LO1 = design.lowInjUp(7);%LO 



try 
    bandSwitch = design.bandSwitch; 
catch 
    bandSwitch = 0; 
end 

E = selfSimp_out(end,3:end); 
%E = selfSimp_out(45,3:45); 
wvFuns = selfSimp_out(1:(end-1),:); 

%find the frequency and dipoles 
frequency = (1.60219e-19/6.6262e-34)*(E(upper) - E(lower)); 

% find voltage/period 
Vpp = design.minSplitField*(design.well(1)+design.well(2)+design.well(3)+design.well(4)+ design.barr(1)+design.barr(2)+design.barr(3)+design.barr(4)); 

%Find rabi frequency 
hbar = 6.58211928e-16;   % in terms of eV 
q = 1.6022e-19; 


minSplitting = E(upper) - E(injector);% resonance of energy levels in both the wells 
minSplitting2 = E(extractor) - E(lower); 

design.E = E; 

z1_simp_iu = dipole(design,upper,injector) 

rabi_freq_iu = abs(design.minSplitField*z1_simp_iu*(1e-5)/(hbar)); 

coupling_energy_iu = hbar*rabi_freq_iu*10^3; 

design.coupling_energy_iu = coupling_energy_iu; 

그리고 내 구조 :

c1 = 

       E: [1x101 double] 
       F: [1x21 double] 
     bandsImg: [] 
      barr: [6 3.8000 1.8000 3.3000 5.2000] 
      barrX: 0.1500 
      dipole1: 3.5718 
     dipole1V: [71x1 double] 
      dipole2: 0.2655 
     dipole2V: [71x1 double] 
     dopeBarr: [0 0 0 0 0] 
     dopeWell: [0 0 0 0 1.9600e+16] 
     elemDens: 2 
     frequency: 3.7630e+12 
      iterFac: 1 
     lowInjUp: [11 16 14 13 10 9 7] 
    minSplitField: -7.3500 
    minSplitting: -0.0019 
      name: ' Modified Amanti deisgn ETH' 
      numPer: 3 
      posMeth: 2 
     splittingV: [1x20 double] 
      well: [12 9.5000 9.5000 9 19.5000] 
      wvFuns: [542x103 double] 
      alpha: [4x1001 double] 
      dipoles: [] 
     elecTemp: 100 
    minSplitting2: [] 
     splittingV2: [] 
      dipole3: [] 

design.E = E;

이 (design.E이 이미 존재하는) 문제를 야기하지만, design.coupling_energy_iu = coupling_energy_iu;하지 않습니다.

+0

시도해도 제대로 작동합니다. 이 코드가 오류를 생성하는 전체 본문입니까? – excaza

+0

확인 된 작동합니다. 귀하의 모든 코드와 오류가 발생한 지점을 정확히 보여줄 수 있습니까? – rayryeng

+0

@excaza : 코드를 추가했습니다. 답장을 보내 주셔서 감사합니다. – alkamid

답변

2

구조체 배열에 새 요소를 할당하려고하면이 문제가 발생합니다.

for k = 1:4; 
    s(k).a = k; 
    s(k).b = k; 
end 
t.a = 5; 
try 
    s(5) = t; 
catch 
    fprintf('This is error1\n'); 
end 
t.b = 5; 
t.c = 5; 
try 
    s(5) = t; 
catch 
    fprintf('This is error2\n'); 
end 

% Possible cure 
s(1).c = []; 
s(5) = t; 
% t.b=[]; s(5) = t; 
fprintf('This works!\n'); 

그러나 코드에서 당신이 어쩌면 모든 필드가 있는지 확인하는 검사의 일종이있을 것이다 :이 요소는 필드의 다른 세트가있는 경우는 명시된 오류, 예를 줄 것이다. 또 다른 해결책은 대신 셀 배열을 사용하는 것입니다.