Code lin 45 strfind not enough imput arguments. I am confused why this is.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
close all;
clearvars;
%clc;
filter_list = {'Sc_30um','V_13um','Ru_8.5um'};
%filter_list = {'Be_10um','B_10um','C_5um','Mg_10um','Al_10um','Ti_12um','V_10um'};
%filter_list = {'Ti_12um','V_10um','Cr_3um','Fe_10um','Cu_10um','Zr_25um','Nb_20um'}
%filter_list = {'Zr_25um','Nb_20um','Mo_7um','Ag_5um','Sn_15um','Ta_3um','W_10um'}
%filter_list = {'Si_10um','Si_5um','Cr_3um','Fe_5um'}
mpath = mfilename('fullpath');
[path, sciptname] = fileparts(mpath);
addpath(genpath(path));
workdir = path;
cd (workdir);
filters = struct;
energy = 10:5:10000;
file_found = struct;
for n_f = 1:length(filter_list)
strpos = strfind(filter_list{n_f},'_');
mat_look = filter_list{n_f}(1:strpos-1);
file_found = dir([filter_list{n_f} '.txt']);
if isempty(file_found)
mat_found = dir([mat_look '*']);
n_d = 0;
if ~isempty(mat_found)
while n_d < length(mat_found)
n_d = n_d +1;
strpos = strfind(mat_found(n_d).name,'_');
mat_found(n_d).mat = mat_found(n_d).name(1:strpos-1);
if ~strcmp(mat_found(n_d).mat,mat_look)
mat_found(n_d) = [];
n_d = n_d -1;
else
file_found = mat_found(n_d);
end
end
end
end
%file_found.str = sscanf(file_found.name,'%s_%fum.txt');
strpos = strfind(file_found.name,'_');
file_found.thick = str2double(file_found.name(strpos+1:end-6));
strpos = strfind(filter_list{n_f},'_');
data = importdata(file_found.name);
filters(n_f).filter_string = data.textdata{1,1};
string_values = textscan(filters(n_f).filter_string,' %s Density=%f Thickness=%f microns');
filters(n_f).material = char(string_values{1});
filters(n_f).density = string_values{2};
filters(n_f).thickness = string_values{3};
filters(n_f).thickness_ask = str2double(filter_list{n_f}(strpos+1:end-2));
filters(n_f).rescale = filters(n_f).thickness_ask/filters(n_f).thickness;
filters(n_f).thickness_rescaled = filters(n_f).thickness*filters(n_f).rescale;
filters(n_f).label = char(strcat(filters(n_f).material,{' '},num2str(filters(n_f).thickness_rescaled),{'um'}));
filters(n_f).E = data.data(:,1);
filters(n_f).T = data.data(:,2).^filters(n_f).rescale;
filters(n_f).Eint = energy;
filters(n_f).Tint = interp1(filters(n_f).E,filters(n_f).T,filters(n_f).Eint,'pchip');
end
lines_col = lines;
%% Figure 1 with filter transmission
%fig1 = figure('Name','Filter Transmission','Position',[50 50 1450 720]);
fig1 = figure('Name','Filter Transmission','Units','normalized','Position',[0.1 0.18 0.85 0.7]);
set(groot,'CurrentFigure',fig1);
set(gca,'FontSize',24);
hold on;
for n_f = 1:length(filter_list)
p(n_f) = plot(filters(n_f).Eint/1e3,filters(n_f).Tint,'-','LineWidth',2,'DisplayName',filters(n_f).label); %#ok<SAGROW>
end
q(1) = patch([4100 4900 4900 4100]/1e3,[1e-6 1e-6 1 1],'b','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Xe L-shell');
%q(2) = patch([3000 3200 3200 3000]/1e3,[1e-6 1e-6 1 1],'r','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Ar K-shell');
%q(3) = patch([1500 2400 2400 1500]/1e3,[1e-6 1e-6 1 1],'g','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Kr L-shell');
set(gca,'TickDir','out');
grid on;
xlim([0.1 10]);
xlabel('Photon Energy (keV)');
%ylim([1e-4 1.0]);
% set(gca, 'YScale', 'log');
ylim([0 1.0]);
ylabel('Transmission');
[~, lgd] = legend([p q(1)],'Location','southeast','FontSize',14);
%[~, lgd] = legend([p],'Location','southeast','FontSize',14);
% legend_patches = findobj(lgd, 'type', 'patch');
% set(legend_patches(1), 'FaceAlpha', 0.3);
% set(legend_patches(2), 'FaceAlpha', 0.3);
% set(legend_patches(3), 'FaceAlpha', 0.3);
lgdline = findobj(lgd, 'type', 'line');
% %% Figure 2 with Ross pairs
% fig2 = figure('Name','Ross pairs','Units','normalized','Position',[0.1 0.18 0.85 0.7]);
% set(groot,'CurrentFigure',fig2);
% set(gca,'FontSize',28);
% hold on;
% p(1) = plot(filters(1).Eint,filters(1).Tint-filters(2).Tint,'-','Color',lines_col(1,:),'LineWidth',1.5,'DisplayName',[filters(1).label '-' filters(2).label]);
% p(2) = plot(filters(2).Eint,filters(2).Tint-filters(1).Tint,'--','Color',lines_col(1,:),'LineWidth',1.5,'DisplayName',[filters(2).label '-' filters(1).label]);
% p(3) = plot(filters(4).Eint,filters(4).Tint-filters(3).Tint,'-','Color',lines_col(2,:),'LineWidth',1.5,'DisplayName',[filters(4).label '-' filters(3).label]);
% p(4) = plot(filters(3).Eint,filters(3).Tint-filters(4).Tint,'--','Color',lines_col(2,:),'LineWidth',1.5,'DisplayName',[filters(3).label '-' filters(4).label]);
% p(5) = plot(filters(4).Eint,filters(4).Tint-filters(5).Tint,'-','Color',lines_col(3,:),'LineWidth',1.5,'DisplayName',[filters(4).label '-' filters(5).label]);
% p(6) = plot(filters(5).Eint,filters(5).Tint-filters(4).Tint,'--','Color',lines_col(3,:),'LineWidth',1.5,'DisplayName',[filters(5).label '-' filters(4).label]);
% p(7) = plot(filters(5).Eint,filters(5).Tint-filters(6).Tint,'-','Color',lines_col(4,:),'LineWidth',1.5,'DisplayName',[filters(5).label '-' filters(6).label]);
% p(8) = plot(filters(6).Eint,filters(6).Tint-filters(5).Tint,'--','Color',lines_col(4,:),'LineWidth',1.5,'DisplayName',[filters(6).label '-' filters(5).label]);
% p(9) = plot(filters(2).Eint,filters(2).Tint-filters(7).Tint,'-','Color',lines_col(5,:),'LineWidth',1.5,'DisplayName',[filters(2).label '-' filters(7).label]);
% p(10) = plot(filters(7).Eint,filters(7).Tint-filters(2).Tint,'--','Color',lines_col(5,:),'LineWidth',1.5,'DisplayName',[filters(7).label '-' filters(2).label]);
% % plot([850 850],[1e-6 1],'--b');
% % plot([1400 1400],[1e-6 1],'--b');
% % plot([3000 3000],[1e-6 1],'--r');
% % plot([4000 4000],[1e-6 1],'--r');
% % plot([1500 1500],[1e-6 1],'--g');
% % plot([2400 2400],[1e-6 1],'--g');
% q(1) = patch([850 1400 1400 850],[1e-6 1e-6 1 1],'b','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Ne K-shell');
% q(2) = patch([3000 4000 4000 3000],[1e-6 1e-6 1 1],'r','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Ar K-shell');
% q(3) = patch([1500 2400 2400 1500],[1e-6 1e-6 1 1],'g','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Kr L-shell');
% plot([0 10000],[0.1 0.1],'-k');
% set(gca,'TickDir','out');
% box on;
% grid on;
% xlim([100 7100]);
% ylim([1.0e-4 1.0]);
% set(gca, 'YScale', 'log');
% xlabel('Photon Energy (eV)');
% ylabel('Transmission Coefficient');
% [~, lgd] = legend([p q],'Location','southeast','FontSize',14);
% legend_patches = findobj(lgd, 'type', 'patch');
% set(legend_patches(1), 'FaceAlpha', 0.3);
% set(legend_patches(2), 'FaceAlpha', 0.3);
% set(legend_patches(3), 'FaceAlpha', 0.3);
% legend_lines = findobj(lgd, 'type', 'line');
% %Echeck = 2000;
% %fprintf('Window peak transmission = %.2f\n',filters(1).Tint(filters(1).Eint==Echeck)-filters(2).Tint(filters(1).Eint==Echeck));
% fprintf('\n');close all;
clearvars;
%clc;
filter_list = {'Sc_30um','V_13um','Ru_8.5um'};
%filter_list = {'Be_10um','B_10um','C_5um','Mg_10um','Al_10um','Ti_12um','V_10um'};
%filter_list = {'Ti_12um','V_10um','Cr_3um','Fe_10um','Cu_10um','Zr_25um','Nb_20um'}
%filter_list = {'Zr_25um','Nb_20um','Mo_7um','Ag_5um','Sn_15um','Ta_3um','W_10um'}
%filter_list = {'Si_10um','Si_5um','Cr_3um','Fe_5um'}
mpath = mfilename('fullpath');
[path, sciptname] = fileparts(mpath);
addpath(genpath(path));
workdir = path;
cd (workdir);
filters = struct;
energy = 10:5:10000;
file_found = struct;
for n_f = 1:length(filter_list)
strpos = strfind(filter_list{n_f},'_');
mat_look = filter_list{n_f}(1:strpos-1);
file_found = dir([filter_list{n_f} '.txt']);
if isempty(file_found)
mat_found = dir([mat_look '*']);
n_d = 0;
if ~isempty(mat_found)
while n_d < length(mat_found)
n_d = n_d +1;
strpos = strfind(mat_found(n_d).name,'_');
mat_found(n_d).mat = mat_found(n_d).name(1:strpos-1);
if ~strcmp(mat_found(n_d).mat,mat_look)
mat_found(n_d) = [];
n_d = n_d -1;
else
file_found = mat_found(n_d);
end
end
end
end
%file_found.str = sscanf(file_found.name,'%s_%fum.txt');
strpos = strfind(file_found.name,'_');
file_found.thick = str2double(file_found.name(strpos+1:end-6));
strpos = strfind(filter_list{n_f},'_');
data = importdata(file_found.name);
filters(n_f).filter_string = data.textdata{1,1};
string_values = textscan(filters(n_f).filter_string,' %s Density=%f Thickness=%f microns');
filters(n_f).material = char(string_values{1});
filters(n_f).density = string_values{2};
filters(n_f).thickness = string_values{3};
filters(n_f).thickness_ask = str2double(filter_list{n_f}(strpos+1:end-2));
filters(n_f).rescale = filters(n_f).thickness_ask/filters(n_f).thickness;
filters(n_f).thickness_rescaled = filters(n_f).thickness*filters(n_f).rescale;
filters(n_f).label = char(strcat(filters(n_f).material,{' '},num2str(filters(n_f).thickness_rescaled),{'um'}));
filters(n_f).E = data.data(:,1);
filters(n_f).T = data.data(:,2).^filters(n_f).rescale;
filters(n_f).Eint = energy;
filters(n_f).Tint = interp1(filters(n_f).E,filters(n_f).T,filters(n_f).Eint,'pchip');
end
lines_col = lines;
%% Figure 1 with filter transmission
%fig1 = figure('Name','Filter Transmission','Position',[50 50 1450 720]);
fig1 = figure('Name','Filter Transmission','Units','normalized','Position',[0.1 0.18 0.85 0.7]);
set(groot,'CurrentFigure',fig1);
set(gca,'FontSize',24);
hold on;
for n_f = 1:length(filter_list)
p(n_f) = plot(filters(n_f).Eint/1e3,filters(n_f).Tint,'-','LineWidth',2,'DisplayName',filters(n_f).label); %#ok<SAGROW>
end
q(1) = patch([4100 4900 4900 4100]/1e3,[1e-6 1e-6 1 1],'b','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Xe L-shell');
%q(2) = patch([3000 3200 3200 3000]/1e3,[1e-6 1e-6 1 1],'r','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Ar K-shell');
%q(3) = patch([1500 2400 2400 1500]/1e3,[1e-6 1e-6 1 1],'g','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Kr L-shell');
set(gca,'TickDir','out');
grid on;
xlim([0.1 10]);
xlabel('Photon Energy (keV)');
%ylim([1e-4 1.0]);
% set(gca, 'YScale', 'log');
ylim([0 1.0]);
ylabel('Transmission');
[~, lgd] = legend([p q(1)],'Location','southeast','FontSize',14);
%[~, lgd] = legend([p],'Location','southeast','FontSize',14);
% legend_patches = findobj(lgd, 'type', 'patch');
% set(legend_patches(1), 'FaceAlpha', 0.3);
% set(legend_patches(2), 'FaceAlpha', 0.3);
% set(legend_patches(3), 'FaceAlpha', 0.3);
lgdline = findobj(lgd, 'type', 'line');
% %% Figure 2 with Ross pairs
% fig2 = figure('Name','Ross pairs','Units','normalized','Position',[0.1 0.18 0.85 0.7]);
% set(groot,'CurrentFigure',fig2);
% set(gca,'FontSize',28);
% hold on;
% p(1) = plot(filters(1).Eint,filters(1).Tint-filters(2).Tint,'-','Color',lines_col(1,:),'LineWidth',1.5,'DisplayName',[filters(1).label '-' filters(2).label]);
% p(2) = plot(filters(2).Eint,filters(2).Tint-filters(1).Tint,'--','Color',lines_col(1,:),'LineWidth',1.5,'DisplayName',[filters(2).label '-' filters(1).label]);
% p(3) = plot(filters(4).Eint,filters(4).Tint-filters(3).Tint,'-','Color',lines_col(2,:),'LineWidth',1.5,'DisplayName',[filters(4).label '-' filters(3).label]);
% p(4) = plot(filters(3).Eint,filters(3).Tint-filters(4).Tint,'--','Color',lines_col(2,:),'LineWidth',1.5,'DisplayName',[filters(3).label '-' filters(4).label]);
% p(5) = plot(filters(4).Eint,filters(4).Tint-filters(5).Tint,'-','Color',lines_col(3,:),'LineWidth',1.5,'DisplayName',[filters(4).label '-' filters(5).label]);
% p(6) = plot(filters(5).Eint,filters(5).Tint-filters(4).Tint,'--','Color',lines_col(3,:),'LineWidth',1.5,'DisplayName',[filters(5).label '-' filters(4).label]);
% p(7) = plot(filters(5).Eint,filters(5).Tint-filters(6).Tint,'-','Color',lines_col(4,:),'LineWidth',1.5,'DisplayName',[filters(5).label '-' filters(6).label]);
% p(8) = plot(filters(6).Eint,filters(6).Tint-filters(5).Tint,'--','Color',lines_col(4,:),'LineWidth',1.5,'DisplayName',[filters(6).label '-' filters(5).label]);
% p(9) = plot(filters(2).Eint,filters(2).Tint-filters(7).Tint,'-','Color',lines_col(5,:),'LineWidth',1.5,'DisplayName',[filters(2).label '-' filters(7).label]);
% p(10) = plot(filters(7).Eint,filters(7).Tint-filters(2).Tint,'--','Color',lines_col(5,:),'LineWidth',1.5,'DisplayName',[filters(7).label '-' filters(2).label]);
% % plot([850 850],[1e-6 1],'--b');
% % plot([1400 1400],[1e-6 1],'--b');
% % plot([3000 3000],[1e-6 1],'--r');
% % plot([4000 4000],[1e-6 1],'--r');
% % plot([1500 1500],[1e-6 1],'--g');
% % plot([2400 2400],[1e-6 1],'--g');
% q(1) = patch([850 1400 1400 850],[1e-6 1e-6 1 1],'b','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Ne K-shell');
% q(2) = patch([3000 4000 4000 3000],[1e-6 1e-6 1 1],'r','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Ar K-shell');
% q(3) = patch([1500 2400 2400 1500],[1e-6 1e-6 1 1],'g','FaceAlpha',0.2,'EdgeColor','none','DisplayName','Kr L-shell');
% plot([0 10000],[0.1 0.1],'-k');
% set(gca,'TickDir','out');
% box on;
% grid on;
% xlim([100 7100]);
% ylim([1.0e-4 1.0]);
% set(gca, 'YScale', 'log');
% xlabel('Photon Energy (eV)');
% ylabel('Transmission Coefficient');
% [~, lgd] = legend([p q],'Location','southeast','FontSize',14);
% legend_patches = findobj(lgd, 'type', 'patch');
% set(legend_patches(1), 'FaceAlpha', 0.3);
% set(legend_patches(2), 'FaceAlpha', 0.3);
% set(legend_patches(3), 'FaceAlpha', 0.3);
% legend_lines = findobj(lgd, 'type', 'line');
% %Echeck = 2000;
% %fprintf('Window peak transmission = %.2f\n',filters(1).Tint(filters(1).Eint==Echeck)-filters(2).Tint(filters(1).Eint==Echeck));
% fprintf('\n');
0 Kommentare
Antworten (1)
Walter Roberson
am 19 Jan. 2024
file_found = dir([filter_list{n_f} '.txt']);
That is returning empty
if isempty(file_found)
So that branch is executed
file_found = mat_found(n_d);
But that does not happen to get executed -- perhaps mat_found = dir([mat_look '*']) is returning empty.
strpos = strfind(file_found.name,'_');
file_found is empty, so file_found.name is expanding to 0 arguments, so the call is effectively to strfind('_')
You also have the more general problem that find_found might happen to match multiple files, so file_found.name might expand to multiple parameters.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Geographic Coordinate Reference Systems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!