How to rename files and put them into structure?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello! I am doing a GUI in appdesigner.
With this line, I can open multiple files.
[file, path] = uigetfile('*.s2p','MultiSelect','on');
In the first image there are two files (example) i am opening.
When I open the files, I get this (second image). In this case I opened 3 files.
So, in my GUI I have an antenna array like this (third image). Now I am trying to assing the files to specific antennas.
For example, I want to say that the file 'sparameters_2,1_3,3.s2p' has the relationship between antenna 2,1 and antenna 3,3. And I want to have a struct with the relationship betwwen all the antennas. So when I open multiple files, my goal is to open every one which has numbers like 3,1_2,2, and to this this to have a struct. Exmaple:
A1 A2 file
1,1 1,2 sparameters_1,1_1,2
1,1 2,1 sparameters_1,1_2,1
...
10,1 3,4 sparameters_10,1_3,4
I don't know what to do to the files... Maybe rename them just to have the numbers... And then how can I assign them like in the example? I am a little lost, if you could give some clue, I would apreciate very much. Thanks!
0 件のコメント
採用された回答
Voss
2022 年 2 月 19 日
編集済み: Voss
2022 年 2 月 19 日
If I understand the situation, there is a limit on the number of antennas you can store in pairs in file names like that. I mean, there is no delimiter between the antenna indices in the antenna_*.s2p file names (unlike the sparameters_*.s2p file names, which use a comma as a delimiter). So say you had 11 antennas, then there would be no way to determine whether 'antenna_11123.s2p' meant antennas (1,11) and (2,3) or antennas (11,1) and (2,3). Your antenna matrix is 3-by-4, but you mention antenna (10,1) in your example, so I don't know whether this is a problem.
(It's also not completely clear to me that you need to use antenna_*.s2p file names at all, when you could select the corresponding sparameters_*.s2p files, which are uniquely decodable. But I'm going by what you showed in the files.png screen shot.)
The following will do what I think you want to do, which is to create an array of structs containing information about which pair of antennas correspond to which sparameters file. However, it will only work for a matrix of antennas of size up to 9-by-9 due to the limitation described above (you could go up to 10x10 and be uniquely decodable, but having each antenna index represented by a single digit makes it easier).
file = {'antenna_2133.s2p' 'antenna_3311.s2p' 'antenna_1112.s2p' 'antenna_1121.s2p'};
file_info = struct();
nums = regexp(file,'_(\d+)\.','tokens');
nums = [nums{:}];
for ii = 1:numel(file)
file_info(ii).A1 = sprintf('%c,%c',nums{ii}{1}([1 2]));
file_info(ii).A2 = sprintf('%c,%c',nums{ii}{1}([3 4]));
file_info(ii).file = sprintf('sparameters_%s_%s',file_info(ii).A1,file_info(ii).A2);
file_info(ii).antenna_file = file{ii}; % just in case you need this too
end
% show the array of structs file_info:
file_info
for ii = 1:numel(file_info)
file_info(ii)
end
7 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!