How to open and read .ffs file matlab?

11 次查看(过去 30 天)
Hello! I have an .ffs file (see image 1).
I am doind this in matlab to get it and open it:
>> [radiationfile, path] = uigetfile('*.ffs');
>> radiationfile = fileread(radiationfile);
But now I don't know how to save the important parts of the file. I just want to save in an array the variables Phi (which corresponds to the first column), Theta (the second column) and so forth for the others.
I want to do this in appDesigner. The user chose some .ffs file and the code save the important variables, which can not always be in the same lines.
Is there any function I don't know to help me? I will send you the file in .txt just for you to understand better. I changed it to .txt because it is not possible to upload a .ffs file. But in the code I want that file to be .ffs
Thank you!!

采纳的回答

Voss
Voss 2022-5-22
% (first, make the attached .txt file an .ffs file)
copyfile('SpiralAntennaBox_v02_FarField_4p5GHz.txt','SpiralAntennaBox_v02_FarField_4p5GHz.ffs');
It looks like readmatrix will work; just specify 'FileType','text' due to the unrecognized extension:
% Option 1: use readmatrix:
data = readmatrix('SpiralAntennaBox_v02_FarField_4p5GHz.ffs','FileType','text')
data = 2701×6
0 0 2.9787 -2.9930 5.3741 -5.4495 0 5.0000 2.0783 -3.2030 5.3140 -4.6461 0 10.0000 1.1357 -3.3278 5.1547 -3.8193 0 15.0000 0.1911 -3.3455 4.9238 -3.0078 0 20.0000 -0.7146 -3.2437 4.6496 -2.2469 0 25.0000 -1.5427 -3.0211 4.3583 -1.5657 0 30.0000 -2.2607 -2.6877 4.0708 -0.9861 0 35.0000 -2.8439 -2.2627 3.8016 -0.5216 0 40.0000 -3.2778 -1.7725 3.5583 -0.1773 0 45.0000 -3.5578 -1.2467 3.3425 0.0490
Or, here's one way to complete the approach you were working on, using fileread:
% Option 2: use fileread:
radiationfile = fileread('SpiralAntennaBox_v02_FarField_4p5GHz.ffs');
idx = strfind(radiationfile,':');
data = str2num(radiationfile(idx(end)+1:end))
data = 2701×6
0 0 2.9787 -2.9930 5.3741 -5.4495 0 5.0000 2.0783 -3.2030 5.3140 -4.6461 0 10.0000 1.1357 -3.3278 5.1547 -3.8193 0 15.0000 0.1911 -3.3455 4.9238 -3.0078 0 20.0000 -0.7146 -3.2437 4.6496 -2.2469 0 25.0000 -1.5427 -3.0211 4.3583 -1.5657 0 30.0000 -2.2607 -2.6877 4.0708 -0.9861 0 35.0000 -2.8439 -2.2627 3.8016 -0.5216 0 40.0000 -3.2778 -1.7725 3.5583 -0.1773 0 45.0000 -3.5578 -1.2467 3.3425 0.0490
  2 个评论
Bárbara Matos
Bárbara Matos 2022-5-22
Thank you very much! I think I will use the fisrt option, because the second option depends on the caracter ':' and it can create some problems on different files.
Thank you again, it works perfectly! :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by