Matlab读取S2P文件

 时间:2024-10-13 06:26:12

1、请查看S2P文件是否如下格式# hz S ma R 50# HZ S RI R 50

2、保存以下脚本function [FRE S11 S21 S12 S22 noise] = ReadS2P(f足毂忍珩ilename) file = fopen(filename); file_temp_s = fopen(".s_parameter_temp.t", 'w'); file_temp_n = fopen(".noise_temp.t", "w"); status = 0; sParameter_context = []; nNoise_context = []; paramete_type = ''; while 1 line = fgetl(file); if(length(line) == 0) continue; end; if(~ischar(line)) break;end if(status == 0 && line(1) == '#') status = 1; paramete_type = line; continue; end if((status == 1 || status == 2) && line(1) ~= '!') status = 2; %sParameter_context = strcat(sParameter_context, line); fprintf(file_temp_s, "%s\n", line); end if(status == 2 && line(1) == '!') status = 3; end if(status == 3 && line(1) ~= '!') %nNoise_context = strcat(nNoise_context, line); fprintf(file_temp_n, "%s\n", line); end end fclose(file_temp_n); fclose(file_temp_s); file_temp_s = dlmread(".s_parameter_temp.t"); file_temp_n = dlmread(".noise_temp.t"); para_list = split(paramete_type, ' '); FRE = file_temp_s(:,1); if(strcmp(para_list(4), 'MA') || strcmp(para_list(4), 'ma')) temp = 2; S11 = file_temp_s(:,temp); temp = temp + 2; S21 = file_temp_s(:,temp); temp = temp + 2; S12 = file_temp_s(:,temp); temp = temp + 2; S22 = file_temp_s(:,temp); temp = temp + 2; end if(strcmp(para_list(4), 'RI') || strcmp(para_list(4), 'ri')) temp = 2; S11 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; S12 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; S21 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; S22 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; end if(strcmp(para_list(4), 'DB') || strcmp(para_list(4), 'db')) temp = 2; S11 = file_temp_s(:,temp); temp = temp + 2; S21 = file_temp_s(:,temp); temp = temp + 2; S12 = file_temp_s(:,temp); temp = temp + 2; S22 = file_temp_s(:,temp); temp = temp + 2; end noise = file_temp_n;end

3、测试代码[S1_FRE S1_S11 S1_S21 S1_S12 S1_S22 S1_Noise] = ReadS2P('data.s2p');

  • matlab数值精度怎么设定
  • MATLAB如何分割字符串?
  • matlab命令历史记录窗口启用
  • 怎么用matlab函数load导入数据
  • matlab如何找到数组中的最大值和位置
  • 热门搜索
    成都到西双版纳旅游 有品位旅游年卡 齐云山旅游攻略 福建宁德旅游 德国旅游地图 遂宁旅游景点大全 暑假去哪里旅游好 青岛旅游景点图片 扬州旅游网 张家港旅游景点