How to rename files and put them into structure?

1 vue (au cours des 30 derniers jours)
Bárbara Matos
Bárbara Matos le 19 Fév 2022
Commenté : Voss le 20 Fév 2022
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!

Réponse acceptée

Voss
Voss le 19 Fév 2022
Modifié(e) : Voss le 19 Fév 2022
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
file_info = 1×4 struct array with fields:
A1 A2 file antenna_file
for ii = 1:numel(file_info)
file_info(ii)
end
ans = struct with fields:
A1: '2,1' A2: '3,3' file: 'sparameters_2,1_3,3' antenna_file: 'antenna_2133.s2p'
ans = struct with fields:
A1: '3,3' A2: '1,1' file: 'sparameters_3,3_1,1' antenna_file: 'antenna_3311.s2p'
ans = struct with fields:
A1: '1,1' A2: '1,2' file: 'sparameters_1,1_1,2' antenna_file: 'antenna_1112.s2p'
ans = struct with fields:
A1: '1,1' A2: '2,1' file: 'sparameters_1,1_2,1' antenna_file: 'antenna_1121.s2p'
  7 commentaires
Bárbara Matos
Bárbara Matos le 19 Fév 2022
Thak you very much for your help! It was precious! :)
I already understand, I will change the name of my files and separate all with commas.
Thank you again! :)
Voss
Voss le 20 Fév 2022
OK great! You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by