- Read all these files and save in a cell array (Use a cell array or array is better way rather than multiple variables names)
- Same for do,d1,d2,d3..... and C1,C2,C3........
- You can run a loop to call multiple figures with different colors and linwidth for the following plots assignments (See FAQ)
I want to reduce the length of my program.It is very repetitive.Since I am not from a programming background can anyone suggest or help me improve my code for plotting multiple beam profiles?
1 回表示 (過去 30 日間)
古いコメントを表示
clc;
clear all;
close all;
%-------Date:041020119--------Data with new pressure guage and 4 filaments---%
%Set for pressure 1e-4Torr Faraday cup grounded and repellor bias of V:-30V
%Filament current was varied for different shots%
%Area of beam%
%DATA PLOTTED AT 13TH SECOND OF THE SHOT%
A=3.14; %Area in cm2 of one FC
calF = 1000/(A*100); % calbration for mA/cm2 100 is for resistance
calF1=1000000/(A*100);%calibration for microA/cm2
a0 =csvread('WAVE0015.CSV',11,0);%PS current 4mA %
a1 =csvread('WAVE0014.CSV',11,0);%PS current 7mA %
a2 =csvread('WAVE0013.CSV',11,0);%PS current 8mA %
a3 =csvread('WAVE0012.CSV',11,0);%PS current 11mA %
a4 =csvread('WAVE0010.CSV',11,0);%PS current 13mA %
a5=csvread('WAVE0011.CSV',11,0);%PS current 16mA %
a6=csvread('WAVE0008.CSV',11,0);%PS current 18mA %
a7=csvread('WAVE0009.CSV',11,0);%PS current 20mA %
a8 =csvread('WAVE0007.CSV',11,0);%PS current 24mA %
a9 =csvread('WAVE0006.CSV',11,0);%PS current 29mA %
a10 =csvread('WAVE0005.CSV',11,0);%PS current 33mA %
a11 =csvread('WAVE0003.CSV',11,0);%PS current 38mA %
a12 =csvread('WAVE0004.CSV',11,0);%PS current 43mA %
a13=csvread('WAVE0001.CSV',11,0);%PS current 53mA %
%--------------------------------------------------------------------------%
%---------4mA-------------------------------------------------------------%
% figure(7);
A1=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y51=mean(a0(46:51,2:12))*calF1;%Average from 9-10 1second%
subplot(4,4,1),plot(A1,Y51,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
% figure(7);
subplot(4,4,1),R1=fit(A1',Y51','gauss1');
plot(R1,'.k');
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Radial distance(mm)');
ylabel('Current (microA/cm2)');
title('4mA');
legend('Data','fit');
hold on
K1=coeffvalues(R1);
B0 = sqrt(2)*K1(3);%i/e definition of divergence%
L0=K1(2);
Z1=9.4*K1(1)*K1(3).^2/1000000;%Correction for converting to miliampere%
%---------7mA-------------------------------------------------------------%
% figure(2);
X=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y=mean(a1(46:51,2:12))*calF1;%Averaged value over 1second%
subplot(4,4,2),plot(X,Y,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(2);
func=fit(X',Y','gauss1');
subplot(4,4,2),plot(func,'.k');
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('7mA');
legend('data','fit');
M=coeffvalues(func);
B1 = sqrt(2)*M(3)
L1=M(2);
%----------------------------------------------------------------------------------------%
Z2=9.4*M(1)*M(3).^2/1000000;
%---------8mA-------------------------------------------------------------%
% figure(3);
X1=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y1=mean(a2(81:101,2:12))*calF1;
subplot(4,4,3),plot(X1,Y1,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
% figure(3);
h=fit(X1',Y1','gauss1');
subplot(4,4,3),plot(h,'.k');
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Radial distance(mm)');
ylabel('Current (microA/cm2)');
title('8mA');
legend('Data','fit');
hold on
M1=coeffvalues(h);
B2 = sqrt(2)*M1(3);
L2=M1(2);
%----------------------------------------------------------------------------------------%
Z3=9.4*M1(1)*M1(3).^2/1000000;
%---------11mA-------------------------------------------------------------%
% figure(4);
X2=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y2=mean(a3(81:101,2:12))*calF;
subplot(4,4,4),plot(X2,Y2,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
% figure(4);
h1=fit(X2',Y2','gauss1');
subplot(4,4,4),plot(h1,'.k');
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('11mA');
legend('Data','fit');
axis([-200 200 0 0.02]);
hold on
M2=coeffvalues(h1);
B3 = sqrt(2)*M2(3);
L3=M2(2);
Z4=9.4*M2(1)*M2(3).^2*10E-3;
%---------13mA-------------------------------------------------------------%
% figure(5);
X3=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y3=mean(a4(81:101,2:12))*calF;
subplot(4,4,5),plot(X3,Y3,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
% figure(5);
h2=fit(X3',Y3','gauss1');
subplot(4,4,5),plot(h2,'.k');
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('13mA');
legend('Data','fit');
axis([-200 200 0 0.02]);
hold on
M3=coeffvalues(h2);
B4 = sqrt(2)*M3(3);
L4=M3(2);
Z5=9.4*M3(1)*M3(3).^2*10E-3;
%---------16mA------------------------------------------------------------%
% figure(6);
X4=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y4=mean(a5(81:101,2:12))*calF;
subplot(4,4,6),plot(X4,Y4,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
%
% figure(6);
h3=fit(X4',Y4','gauss1');
subplot(4,4,6),plot(h3,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('16mA');
legend('Data','fit');
axis([-200 200 0 0.05]);
hold on
M4=coeffvalues(h3);
B5 = sqrt(2)*M4(3);
L5=M4(2);
Z6=9.4*M4(1)*M4(3).^2*10E-3;
%---------18mA-------------------------------------------------------------%
% figure(6);
X5=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y5=mean(a6(81:101,2:12))*calF;
subplot(4,4,7),plot(X5,Y5,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
h4=fit(X5',Y5','gauss1');
subplot(4,4,7),plot(h4,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('18mA');
legend('Data','fit');
axis([-200 200 0 0.05]);
hold on
M5=coeffvalues(h4);
B6 = sqrt(2)*M5(3);
L6=M5(2);
Z7=9.4*M5(1)*M5(3).^2*10E-3;
%---------20mA-------------------------------------------------------------%
% figure(6);
X6=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y6=mean(a7(81:101,2:12))*calF;
subplot(4,4,8),plot(X6,Y6,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L=fit(X6',Y6','gauss1');
subplot(4,4,8),plot(L,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('20mA');
legend('Data','fit');
axis([-200 200 0 0.05]);
hold on
M6=coeffvalues(L);
B7 = sqrt(2)*M6(3);
L7=M6(2);
Z8=9.4*M6(1)*M6(3).^2*10E-3;
%---------24mA-------------------------------------------------------------%
% figure(6);
X7=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y7=mean(a8(81:101,2:12))*calF;
subplot(4,4,9),plot(X7,Y7,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L11=fit(X7',Y7','gauss1');
subplot(4,4,9),plot(L11,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('24mA');
legend('Data','fit');
axis([-200 200 0 0.05]);
hold on
M7=coeffvalues(L11);
B8 = sqrt(2)*M7(3);
L71=M7(2);
Z9=9.4*M7(1)*M7(3).^2*10E-3;
%---------29mA-------------------------------------------------------------%
% figure(6);
X8=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y8=mean(a9(81:101,2:12))*calF;
subplot(4,4,10),plot(X8,Y8,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L21=fit(X8',Y8','gauss1');
subplot(4,4,10),plot(L21,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('29mA');
legend('Data','fit');
axis([-200 200 0 0.1]);
hold on
M8=coeffvalues(L21);
B9 = sqrt(2)*M8(3);
L8=M8(2);
Z10=9.4*M8(1)*M8(3).^2*10E-3;
%---------33mA-------------------------------------------------------------%
% figure(6);
X9=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y9=mean(a10(36:41,2:12))*calF;%Averaged value over 7:8 =1 second%
subplot(4,4,11),plot(X9,Y9,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L31=fit(X9',Y9','gauss1');
subplot(4,4,11),plot(L31,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('33mA');
legend('Data','fit');
axis([-200 200 0 0.1]);
hold on
M9=coeffvalues(L31);
B10 = sqrt(2)*M9(3);
L9=M9(2);
Z11=9.4*M9(1)*M9(3).^2*10E-3;
%---------38mA-------------------------------------------------------------%
% figure(6);
X10=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y10=mean(a11(51:77,2:12))*calF;
subplot(4,4,12),plot(X10,Y10,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L41=fit(X10',Y10','gauss1');
subplot(4,4,12),plot(L41,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('38mA');
legend('Data','fit');
axis([-200 200 0 0.1]);
hold on
M10=coeffvalues(L41);
B11 = sqrt(2)*M10(3);
L10=M10(2);
Z12=9.4*M10(1)*M10(3).^2*10E-3;
%---------43mA-------------------------------------------------------------%
% figure(6);
X11=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y11=mean(a12(81:101,2:12))*calF;
subplot(4,4,13),plot(X11,Y11,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L51=fit(X11',Y11','gauss1');
subplot(4,4,13),plot(L51,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('43mA');
legend('Data','fit');
axis([-200 200 0 0.1]);
hold on
M11=coeffvalues(L51);
B12 = sqrt(2)*M11(3);
L11=M11(2);
Z13=9.4*M11(1)*M11(3).^2*10E-3;
%---------53mA-------------------------------------------------------------%
% figure(6);
X12=[-120,-96,-72,-48,-24,0,24,48,72,96,120];%Axial Distance%
Y12=mean(a13(51:77,2:12))*calF;%Changed the averaging interval due to noise between 15-20s%
subplot(4,4,14),plot(X12,Y12,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
% figure(6);
L61=fit(X12',Y12','gauss1');
subplot(4,4,14),plot(L61,'.k');
xlabel('Radial distance(mm)');
ylabel('Current (mA/cm2)');
title('53mA');
legend('Data','fit');
axis([-200 200 0 0.1]);
hold on
M12=coeffvalues(L61);
B13 = sqrt(2)*M12(3);
L12=M12(2);
Z14=9.4*M12(1)*M12(3).^2*10E-3;
%-------------------Beam Radius(mm)--------------------------------------------------------------------%
figure(7);
I_int=[Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11,Z12,Z13,Z14];%INTEGRATED CURRENT%
Ips=[4,7,8,11,13,16,18,20,24,29,33,38,43,53];%Power supply Current%
Ib=[20,34,44,59,76,94,105,121,141,176,199,220,242,280]/7;%Beam current%
Ig=Ips-Ib;
B=[B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,B13];
plot(Ips,B,'o','LineWidth',2,'MarkerSize',12);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Extracted Current(mA)');
ylabel('Beam Radius(mm)');
title('Beam Radius vs Extracted Current');
axis([0 55 0 200]);
%----------------Beam divergence----------------------------------------------------------------------------------------------%
figure(8);
d0=(180/3.14)*atan((B0-55)/(628));
d1=(180/3.14)*atan((B1-55)/(628));
d2=(180/3.14)*atan((B2-55)/(628));
d3=(180/3.14)*atan((B3-55)/(628));
d4=(180/3.14)*atan((B4-55)/(628));
d5=(180/3.14)*atan((B5-55)/(628));
d6=(180/3.14)*atan((B6-55)/(628));
d7=(180/3.14)*atan((B7-55)/(628));
d8=(180/3.14)*atan((B8-55)/(628));
d9=(180/3.14)*atan((B9-55)/(628));
d10=(180/3.14)*atan((B10-55)/(628));
d11=(180/3.14)*atan((B11-55)/(628));
d12=(180/3.14)*atan((B12-55)/(628));
d13=(180/3.14)*atan((B13-55)/(628));
Divergence=[d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13];
plot(Ips,Divergence,'o','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Extracted Current(mA))');
ylabel('Beam divergence(Degree)');
title('Beam Divergence vs Extracted');
axis([0 55 0 10]);
figure(9)
plot(Ig,Divergence,'s','LineWidth',2,'MarkerSize',12);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel('Grid Current(mA)');
ylabel('Beam Divergence(Degree');
title('Beam Divergence vs Grid Current');
axis([0 15 0 10]);
%--------------------------------------------
l=a10(:,1);%time in seconds%
C1=a10(:,2)*calF;
C2=a10(:,3)*calF;
C3=a10(:,4)*calF;
C4=a10(:,5)*calF;
C5=a10(:,6)*calF;
C6=a10(:,7)*calF;
C7=a10(:,8)*calF;
C8=a10(:,9)*calF;
C9=a10(:,10)*calF;
C10=a10(:,11)*calF;
C11=a10(:,12)*calF;
figure();
plot(l,C1,'-r','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C2,'.k','LineWidth',2,'MarkerSize',12);
hold on
plot(l,C3,'.g','LineWidth',2,'MarkerSize',12);
hold on
plot(l,C4,'.m','LineWidth',2,'MarkerSize',12);
hold on
plot(l,C5,'sk','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C6,'ob','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C7,'--c','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C8,'--r','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C9,'ok','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C10,'--xr','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C11,'b','LineWidth',2,'MarkerSize',5);
hold on
grid on
set (gca,'fontsize',16, 'fontweight', 'b')
xlabel('Shot duration (s)');
ylabel('Current density (mA/cm2)');
title('Current in different channel');
legend('c1','C2','C3','C4','C5','C6','C7','C8','C9','C10','C11');
hold on
figure()
plot(Ips,Divergence,'or','LineWidth',2,'MarkerSize',8);
hold on
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel(' Extracted Current(mA))');
ylabel('Beam divergence(Degree)');
title('Beam Divergence ');
axis([0 60 0 10])
figure()
plot(I_int,Divergence,'xk','LineWidth',2,'MarkerSize',8);
grid on
hold on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel(' Beam Current(mA))');
ylabel('Beam divergence(Degree)');
title('Beam Divergence ');
axis([0 60 0 10])
figure()
plot(Ig,Divergence,'>','LineWidth',2,'MarkerSize',8);
grid on
hold on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel(' Grid Current(mA))');
ylabel('Beam divergence(Degree)');
title('Beam Divergence ');
%_____________________________________________________________________________
figure()
MM1=100*Ips/1000^1.5;
MM2=Ig./Ips;
MM3=Ig./Ib;
MM4=100*Ib/1000^1.5;
plot(100*Ips/1000^1.5,Ig./Ips,'or','LineWidth',2,'MarkerSize',8);
hold on
grid on
MM=fit(MM1',MM2','poly2');
plot(MM,'.r');
plot(100*Ib/1000^1.5,Ig./Ib,'sk','LineWidth',2,'MarkerSize',8);
grid on
LL=fit(MM4',MM3','poly2');
plot(LL,'.k');
hold on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel(' Perveance');
ylabel('Percentage grid current ratio');
title('Perveance ');
legend('Extracted current','Fit ext','Beam Current','Fit b');
%--------------------------------------------------------------------------------------------------------------------------
figure()
plot(Ib,I_int,'or','LineWidth',2,'MarkerSize',8);
hold on
plot(Ips,I_int,'sk','LineWidth',2,'MarkerSize',8);
hold on
x = linspace(0,60);
y = linspace(0,60);
plot(x,y);
grid on
set (gca,'fontsize',10, 'fontweight', 'b')
xlabel(' Current(mA)');
ylabel(' Integrated Current(mA)');
legend('Beam current','Extracted current')
0 件のコメント
採用された回答
KALYAN ACHARJYA
2019 年 12 月 28 日
編集済み: KALYAN ACHARJYA
2019 年 12 月 28 日
a0 =csvread('WAVE0015.CSV',11,0);%PS current 4mA %
a1 =csvread('WAVE0014.CSV',11,0);%PS current 7mA %
a2 =csvread('WAVE0013.CSV',11,0);%PS current 8mA %
a3 =csvread('WAVE0012.CSV',11,0);%PS current 11mA %
a4 =csvread('WAVE0010.CSV',11,0);%PS current 13mA %
a5=csvread('WAVE0011.CSV',11,0);%PS current 16mA %
a6=csvread('WAVE0008.CSV',11,0);%PS current 18mA %
a7=csvread('WAVE0009.CSV',11,0);%PS current 20mA %
a8 =csvread('WAVE0007.CSV',11,0);%PS current 24mA %
a9 =csvread('WAVE0006.CSV',11,0);%PS current 29mA %
a10 =csvread('WAVE0005.CSV',11,0);%PS current 33mA %
a11 =csvread('WAVE0003.CSV',11,0);%PS current 38mA %
a12 =csvread('WAVE0004.CSV',11,0);%PS current 43mA %
a13=csvread('WAVE0001.CSV',11,0);%PS current 53mA %
One Better Way:
figure();
plot(l,C1,'-r','LineWidth',2,'MarkerSize',5);
hold on
plot(l,C2,'.k','LineWidth',2,'MarkerSize',12);
hold on
plot(l,C3,'.g','LineWidth',2,'MarkerSize',12);
............................
3 件のコメント
Stephen23
2019 年 12 月 28 日
"What is the command to extract data from Cell array?"
Indexing:
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!