关于FOR XML PATH('')的小疑点,在线

本文介绍了一个具体的SQL查询案例,通过使用FORXML PATH功能来生成带有工作计划的文本消息。展示了如何将表中数据转换为所需格式,并提供了解决方案以改进输出结果。
关于FOR XML PATH('')的小问题,在线求助
我有一个表是这样的
想按一下的查询连成想要的句子:
SELECT '西门子dp平台核实:你好,平台已登记你本周的工作计划。'+
(SELECT * FROM #abc FOR XML PATH(''))+'祝你工作愉快!'


结果很难看:西门子dp平台核实:你好,平台已登记你本周的工作计划。<a>星期一</a><b>,上午公司会议</b><c>,下午公司会议。</c><a>星期一</a><b>,上午公司会议</b><c>,下午项目拜访。</c><a>星期五</a><b>,上午休假</b><c>,下午门店拜访。</c><a>星期四</a><b>,上午促销活动</b><c>,下午出差。</c><a>星期三</a><b>,上午Seminar</b><c>,下午代理商沟通。</c><a>星期二</a><b>,上午公司会议</b><c>,下午培训。</c><a>星期一</a><b>,上午门店拜访</b><c>,下午项目拜访。</c>祝你工作愉快!
 

------解决方案--------------------------------------------------------
SELECT '西门子dp平台核实:你好,平台已登记你本周的工作计划。'+
stuff((SELECT ','+a FROM (select a+b+c as a from #abc)a FOR XML PATH('')),1,1,'')+'祝你工作愉快!'
------解决方案--------------------------------------------------------
SELECT '西门子dp平台核实:你好,平台已登记你本周的工作计划。'+
(SELECT ''+a+b+c FROM #abc FOR XML PATH(''))+'祝你工作愉快!'

具体请点击:http://www.verydemo.com/demo_c92_i211128.html

如何基于这段代码“# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license # PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford # Example usage: python train.py --data VOC.yaml # parent # ├── yolov5 # └── datasets # └── VOC ← downloads here (2.8 GB) # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] path: ../datasets/VOC train: # train images (relative to 'path&#39;) 16551 images - images/train2012 - images/train2007 - images/val2012 - images/val2007 val: # val images (relative to 'path&#39;) 4952 images - images/test2007 test: # test images (optional) - images/test2007 # Classes names: 0: aeroplane 1: bicycle 2: bird 3: boat 4: bottle 5: bus 6: car 7: cat 8: chair 9: cow 10: diningtable 11: dog 12: horse 13: motorbike 14: person 15: pottedplant 16: sheep 17: sofa 18: train 19: tvmonitor # Download script/URL (optional) --------------------------------------------------------------------------------------- download: | import xml.etree.ElementTree as ET from tqdm import tqdm from utils.general import download, Path def convert_label(path, lb_path, year, image_id): def convert_box(size, box): dw, dh = 1. / size[0], 1. / size[1] x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2] return x * dw, y * dh, w * dw, h * dh in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml&#39;) out_file = open(lb_path, 'w&#39;) tree = ET.parse(in_file) root = tree.getroot() size = root.find('size&#39;) w = int(size.find('width&#39;).text) h = int(size.find('height&#39;).text) names = list(yaml['names'].values()) # names list for obj in root.iter('object&#39;): cls = obj.find('name&#39;).text if cls in names and int(obj.find('difficult&#39;).text) != 1: xmlbox = obj.find('bndbox&#39;) bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax&#39;)]) cls_id = names.index(cls) # class id out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n&#39;) # Download dir = Path(yaml['path']) # dataset root dir url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/' urls = [f'{url}VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images f'{url}VOCtest_06-Nov-2007.zip', # 438MB, 4953 images f'{url}VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images download(urls, dir=dir / 'images', delete=False, curl=True, threads=3) # Convert path = dir / 'images/VOCdevkit' for year, image_set in ('2012', 'train&#39;), ('2012', 'val&#39;), ('2007', 'train&#39;), ('2007', 'val&#39;), ('2007', 'test&#39;): imgs_path = dir / 'images' / f'{image_set}{year}' lbs_path = dir / 'labels' / f'{image_set}{year}' imgs_path.mkdir(exist_ok=True, parents=True) lbs_path.mkdir(exist_ok=True, parents=True) with open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt&#39;) as f: image_ids = f.read().strip().split() for id in tqdm(image_ids, desc=f'{image_set}{year}&#39;): f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path lb_path = (lbs_path / f.name).with_suffix('.txt&#39;) # new label path f.rename(imgs_path / f.name) # move image convert_label(path, lb_path, year, id) # convert labels to YOLO format ”下载VOC数据集。
08-30
%% 参数设置Fs = 44100; % 采样频率 (Hz)fcut_list = [10, 21; % 滤波器1截止频率 [低, 高] (Hz) 21, 42; 42, 85; 85, 170; 170, 500; 500, 1000; 1000, 2000; % 滤波器2截止频率 2000, 4000; 4000, 8000 ]; % 滤波器3截止频率N = 4096; % 滤波器阶数windowType = 'hamming'; % 窗函数类型%windowType = 'hann'; % 窗函数类型%windowType = 'kaiser'; % 窗函数类型%windowType = 'blackman'; % 窗函数类型N_fft = 8192; % 频响分析点数%% 窗函数参数表(主瓣系数和旁瓣衰减)windowParams = struct(... 'blackman', struct('C',12, 'attenuation',-74),... 'hamming', struct('C',4, 'attenuation',-41),... 'hann', struct('C',4, 'attenuation',-31),... 'kaiser', struct('C',4.5,'attenuation',-53));%% 参数校验if ~isfield(windowParams, windowType) error('不支持的窗类型,可选: blackman/hamming/hann/kaiser&#39;);end%% 生成窗函数if strcmpi(windowType, 'kaiser&#39;) beta = 5; % Kaiser窗参数 win = kaiser(N+1, beta);else win = feval(lower(windowType), N+1); end%% 设计三个并联滤波器num_filters = size(fcut_list,1);b = cell(num_filters, 1);% for k = 1:num_filters% if any(fcut_list(k,:) >= Fs/2)% error('滤波器%d截止频率超过Nyquist频率(%.1fHz)', k, Fs/2);% end% Wn = fcut_list(k,:)/(Fs/2);% b{k} = fir1(N, Wn, 'bandpass', win); % 设计带通滤波器% endmin_transition = 43.07; % 最小过渡带宽度(Hz)transition_ratio = 0.1; % 过渡带占带宽比例for k = 1:num_filters % 1. 安全检查 fLow = fcut_list(k,1); fHigh = fcut_list(k,2); % 截止频率有效性验证 if fHigh >= Fs/2 error('滤波器%d截止频率超过Nyquist频率(%.1fHz)', k, Fs/2); end if fLow >= fHigh error('滤波器%d截止频率范围无效(fLow >= fHigh)', k); end % 2. 计算带宽和过渡带 BW = fHigh - fLow; % 通带带宽 delta_f = max(transition_ratio * BW, min_transition); % 动态过渡带 disp(delta_f); % 3. 自动计算阶数 (基于Hamming窗公式) N = ceil(4 * Fs / delta_f); % 主瓣宽度约束 N = N + mod(N,2); % 强制偶阶数 disp(N); % 4. 带通滤波器设计 Wn = [fLow fHigh]/(Fs/2); % 归一化截止频率 b{k} = fir1(N, Wn, 'bandpass', hamming(N+1)); % 动态阶数设计 % 5. 设计参数输出 fprintf('滤波器%d: BW=%.1fHz, N=%d, Δf=%.1fHz\n',... k, BW, N, delta_f);end%% 幅频响应分析与绘图figure('Position',[100,100,1400,900],'Color','w&#39;);colors = {'#E74C3C','#2ECC71','#3498DB'}; % 红/绿/蓝配色H_total = zeros(N_fft,1);lineStyles = {'--', ':', '-.'}; % 不同滤波器的虚线样式% 绘制单个滤波器响应for k = 1:num_filters [H, f] = freqz(b{k}, 1, N_fft, Fs); H_mag = 20*log10(abs(H)); % 计算3dB带宽 try [bw, f_low, f_high, threshold] = calculate_3dB_bandwidth(f, H_mag, true); catch ME warning('滤波器%d带宽计算失败: %s', k, ME.message); continue; end % 绘制幅频响应 semilogx(f, H_mag, 'Color', colors{k}, 'LineWidth', 1.5,... 'DisplayName', sprintf('Filter %d',k)); hold on; % 标记3dB点坐标 plot(f_low, threshold, 'o', 'MarkerSize',6,... 'MarkerFaceColor',colors{k}, 'MarkerEdgeColor','k&#39;); text(f_low, threshold-4, sprintf('%.1fHz\\n%.1fdB',f_low,threshold),... 'Color',colors{k}, 'FontSize',8, 'VerticalAlignment','top&#39;); plot(f_high, threshold, 'o', 'MarkerSize',6,... 'MarkerFaceColor',colors{k}, 'MarkerEdgeColor','k&#39;); text(f_high, threshold-4, sprintf('%.1fHz\\n%.1fdB',f_high,threshold),... 'Color',colors{k}, 'FontSize',8, 'VerticalAlignment','top&#39;); % 标记设计截止频率 design_fc = fcut_list(k,:); line([design_fc(1) design_fc(1)], ylim,... 'LineStyle',':', 'Color',[0.4 0.4 0.4], 'LineWidth',1.2); text(design_fc(1), max(ylim)-5, sprintf('设计低端\\n%.1fHz',design_fc(1)),... 'Color',[0.4 0.4 0.4], 'FontSize',8, 'HorizontalAlignment','center&#39;); line([design_fc(2) design_fc(2)], ylim,... 'LineStyle',':', 'Color',[0.4 0.4 0.4], 'LineWidth',1.2); text(design_fc(2), max(ylim)-5, sprintf('设计高端\\n%.1fHz',design_fc(2)),... 'Color',[0.4 0.4 0.4], 'FontSize',8, 'HorizontalAlignment','center&#39;); % 标注带宽值 text(mean([f_low, f_high]), threshold-8,... sprintf('BW_{3dB} = %.1f Hz', bw),... 'Color', colors{k}, 'HorizontalAlignment', 'center',... 'FontSize', 9, 'BackgroundColor','w&#39;); H_total = H_total + H; end%% 绘制总响应H_total_abs = abs(H_total);H_total_db = 20*log10(H_total_abs);semilogx(f, H_total_db, 'k', 'LineWidth', 2,... 'DisplayName', 'Combined Response&#39;);%% 图形美化xlabel('Frequency (Hz)&#39;);ylabel('Magnitude (dB)&#39;);title(['Parallel Filter Bank Response (', windowType, ' Window)']);set(gca, 'XScale','log', 'XMinorGrid','on', 'XMinorTick','on',... 'XTick',[20 50 100 200 500 1000 2000 5000 10000 20000],... 'XTickLabel',{'20','50','100','200','500','1k','2k','5k','10k','20k'});grid on;legend('Location','best&#39;);xlim([20, 20000]);ylim([-120, 5]);%% 改进的3dB带宽计算函数function [bw_3db, f_low, f_high, threshold] = calculate_3dB_bandwidth(f, H_mag, is_dB)% 输入参数校验validateattributes(f, {'numeric'}, {'vector'});validateattributes(H_mag, {'numeric'}, {'vector','size',size(f)});if nargin < 3, is_dB = false; end% 单位转换if ~is_dB H_mag = 20*log10(abs(H_mag) + eps); end% 峰值定位与插值[~, idx] = max(H_mag);if idx <= 1 || idx >= numel(H_mag) error('峰值位于端点&#39;);end% 二次多项式插值delta = 0.5*(H_mag(idx-1)-H_mag(idx+1))/(2*H_mag(idx)-H_mag(idx-1)-H_mag(idx+1));peak_refined = H_mag(idx) - 0.25*(H_mag(idx-1)-H_mag(idx+1))*delta;threshold = peak_refined - 3;% 低频交点插值idx_low = find(diff(sign(H_mag(1:idx) - threshold)) > 0, 1, 'last&#39;);if isempty(idx_low) error('未找到低频交点&#39;);endx_low = f(idx_low:idx_low+1);y_low = H_mag(idx_low:idx_low+1) - threshold;f_low = interp1(y_low, x_low, 0, 'linear&#39;);% 高频交点插值idx_high = find(diff(sign(H_mag(idx:end) - threshold)) < 0, 1, 'first&#39;) + idx -1;if isempty(idx_high) error('未找到高频交点&#39;);endx_high = f(idx_high:idx_high+1);y_high = H_mag(idx_high:idx_high+1) - threshold;f_high = interp1(y_high, x_high, 0, 'linear&#39;);% 带宽计算bw_3db = f_high - f_low;% 结果校验if bw_3db <=0 || bw_3db > f(end)-f(1) error('无效带宽值&#39;);endend,上面代码报错。> 位置:bandpassfiltertest2 (273 行) 索引超过数组元素的数量。索引不能超过 3。出错 bandpassfiltertest2 (278 行) semilogx(f, H_mag, 'Color', colors{k}, 'LineWidth', 1.5,...,
05-14
修改代码,使代码符合下面模型model = @(params,X) params(1)*X(:,1).^(params(6)) + params(2)*X(:,2).^(params(7)) + ... params(3)*X(:,3).^(params(8)) + params(4)*X(:,4).^(params(9))+ ... params(5)*X(:,5).^(params(10)) ;其中参数6,7,8,9,10是从-8到8的整数%% 全局参数初始化clear; close all;c = 3e8; % 光速(m/s)lambda = 1550e-9; % 输入光波长(m)P_opt = 10e-3; % 输入光功率(W)L = 0.03; % 电极长度(m)fm_range = linspace(0.1e6,100e9,10000); % 1MHz-100GHzbase_params = struct(... 'Vpi', 3,... % 半波电压 'P_rf_dBm', 0,... % 射频功率(0dBm) 'R', 47,... % 电极阻抗 'alpha_m_dB', 10,... % 微波损耗(dB/m) 'delta', 2.7e-10,...% 速度失配参数(s/m) 'L', L,... 'P_opt', P_opt);%% 执行参数扫描与绘图 % 参数扫描范围定义param_config = { {'Vpi', linspace(0.3,10,100), 'V_{\pi} (V)', 'linear'},... {'P_rf_dBm', linspace(-60,20,100), 'P_{rf} (dBm)', 'linear'},... {'R', linspace(1,100,100), 'R (\Omega)', 'linear'},... {'alpha_m_dB', linspace(0,50,100), '\alpha_m (dB/m)', 'linear'},... {'delta', linspace(2e-10,20e-10,100), '\delta (s/m)', 'linear'},... {'m', linspace(0.01,10,100), '调制深度m', 'linear'} % 新增调制深度m参数};%% 任务1-5:绘制f3dB参数曲线figure('Position',[200,50,1000,700],'Name','f3dB vs Parameters&#39;);for i = 1:5 [X, ~, f3dB] = parameter_sweep(base_params, param_config{i}{1}, param_config{i}{2}, fm_range); subplot(2,3,i); if strcmp(param_config{i}{4}, 'log&#39;) semilogx(X, f3dB/1e9, 'LineWidth',2); else plot(X, f3dB/1e9, 'LineWidth',2); end xlabel(param_config{i}{3}), ylabel('f_{3dB} (GHz)&#39;); title([param_config{i}{3} ' 对f_{3dB}的影响']); grid on;end%% 任务6-10:绘制K值曲线figure('Position',[300,50,1000,700],'Name',&#x27
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值