Info
This question is closed. Reopen it to edit or answer.
How can I write all values of for loop to uitable without overwriting , as following
    2 views (last 30 days)
  
       Show older comments
    
        Tmin=str2double(get(handles.edit43,'String'));
        Tmax=str2double(get(handles.edit44,'String'));
    for T=Tmin:1:Tmax
        Y=(T+0.511)/0.511; 
        B=sqrt(1-(1/Y^.2)); 
        N=get(handles.popupmenu1,'value');
        Z=get(handles.popupmenu1,'value');
        D=(5.09978e-29)*N*Z/B.^2;
        I=get(handles.popupmenu1,'value');
        G=(B.^2)*(Y.^2)*1.022/I;
        SP_ion=D*(log(G)-(B.^2));
        SP1_ion=SP_ion*10^-6; 
        p=get(handles.popupmenu1,'value');
        SP2_ion=(SP_ion/p)*10^-2;
        SP_rad=Z*T*SP_ion/750;
        SP1_rad=SP_rad*10^-6; 
        SP2_rad=(SP_rad/p)*10^-2;
        C1=[T;SP_ion;SP1_ion;SP2_ion;SP_rad;SP1_rad;SP2_rad];
        L=num2cell(C1');
    end
        headers1 = {'E(MeV)','SP_ion(MeV/m)','SP_ion(MeV/cm)','SP_ion(MeV*cm^2/g)','SP_rad(MeV/m)','SP_rad(MeV/cm)','SP_rad(MeV*cm^2/g)'};
        colFormat1 = {'short','short'}; 
        f1 = figure('Name','SP');  
        t = uitable('Parent',f1,'Data',L,'ColumnName',headers1,'ColumnFormat',colFormat1,'Units', 'Normalized', 'Position',[0, 0, 1, 1]);
1 Comment
  Mario Malic
      
 on 25 Aug 2020
				
      Edited: Mario Malic
      
 on 25 Aug 2020
  
			You overwrite it in your code. Make your variables vectors
ii = 1;
for T=Tmin:1:Tmax
        Y(ii,1) =(T+0.511)/0.511; % I see that you're working with rows so,
                                  % you can use this indexing or use Y(ii) and 
                                  % transpose it later as you did before
        % Index the rest of variables where appropriate
        ii = ii+1;
end
If you use row indexing then set the line
C1=[T SP_ion SP1_ion SP2_ion SP_rad SP1_rad SP2_rad];
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
