Extract Values from String with sscanf

2 views (last 30 days)
Alex Perrakis
Alex Perrakis on 5 May 2022
Commented: Alex Perrakis on 10 May 2022
Hallo Guys and Gals,
i have following code:
clear
close all
addpath(genpath('../../Functions'))
%Parameters for GRR
appraisersCount = 4; gapCount =118; measurementsPerSample = 15;
amountOfLayers = 3;
% Choose Folder for Gap Analysis
URL = uigetdir('C:\_Daten\Messungen 3.5.2022\');
% tic
% Open URL
appraisers = dir(URL); appraisers(1:2) = [];
counter = 0;
% for a = 1:appraisersCount
% samplesURL = [URL '\' appraisers(a).name];
% samples = dir(samplesURL); samples(1:2) = [];
% measurementsURL = [URL '\' appraisers(s+2).name];
measurements = dir(URL); measurements(1:2) = [];
% folderspec = 'C:\_Daten\Messungen\WS\Teil 8_1\Teil 8';
% D = dir('C:\_Daten\Messungen\WS\Teil 8_1\Teil 8\*.csv');
rowscounter=41;
for s = 1:rowscounter
% measurementsURL = [URL '\' appraisers(s+2).name];
% measurements = dir(URL); measurements(1:2) = [];
% %
% for m = 1:measurementsPerSample
% counter=counter+1;
% measurementURL = [measurementsURL '\' measurements(m).name];
file=fullfile( URL, measurements(s,1).name);
% table=readtable(file);
fid = fopen( file );
%
wellenlaenge = fgetl(fid);
wellenlaenge = sscanf(wellenlaenge,'%s');
%wellenlaenge = strrep(wellenlaenge,' ',';');
wellenlaenge = strrep(wellenlaenge,',','.');
wellenlaenge = sscanf(wellenlaenge,'%f');
%
% dataColumns = length(frequencies)*2; %*2 cause data contain real + imag
stringData = fscanf(fid,'%s');
% stringData = strrep(stringData,',-1,',',"-1",');
% stringData = strrep(stringData,',1,',',"1",');
% stringData = strrep(stringData,',0,',',"0",');
% stringData = strrep(stringData,'","',' ');
% stringData = strrep(stringData,',"',' ');
% stringData = strrep(stringData,'",',' ');
% stringData = strrep(stringData,'"',' ');
stringData = strrep(stringData,',','.');
%
data = sscanf(stringData, '%f');
% %
% data = reshape(data,dataColumns,[]);
data = data';
reflect(s,:)=data(:,1:125);
% end
%end
end
And i am trying to read the first line of the .csv file i posted with fgetl, nevertheless for some reason it wants to start the values of the first line with 0. while the values are like 902.1, rund the code as it is and you understand what i mean.
  10 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!