Effacer les filtres
Effacer les filtres

How to skip the first line from text file?

9 vues (au cours des 30 derniers jours)
sivalogan satchithanandamoorthy
I have this multi-import file, which ask user to importchose text and csv file. My text file columns information on the first row and I want to skip the first line. Any help would be much appreciated.
Sincerely
siva
clear
clc
[fileName,filePath] = uigetfile({'*.csv';'*.txt'},'Pick a file','MultiSelect','on'); %filePath is were the folder address is stored
if isnumeric(fileName); %fileName is were the file address stored
disp('Please pick multiple file');
return;
end
pathToFile = fullfile(filePath,fileName); % getting file name and folder name
x= size(pathToFile,2); % size of the pathToFile
disp('Stress and strain column in csv format are as follows: 8 & 7');
disp('Stress and strain column in txt format are as follows: 4 & 5');
prompt ='Please choose the Stress column from csv format';
stress_column_csv =input(prompt);
prompt ='Please choose the strain column from csv format';
strain_column_csv=input(prompt);
prompt ='Please choose the Stress column from txt format';
stress_column_txt=input(prompt);
prompt ='Please choose the strain column from txt format';
strain_column_txt=input(prompt);
for i=1:x
[pathstr, name, ext{i}] = fileparts(pathToFile{i}); %had to add this line to get the file extension
store = importdata(pathToFile{i});
if ext{i} == '.csv'
[val,idx] = max(store.data(:,strain_column_csv)); % finding the max value
c ={idx}; % idx contain cell value.
stress{i}=store.data(1:c{1},stress_column_csv);
strain{i} =store.data(1:c{1},strain_column_csv);
else if ext{i}=='.txt'
% [val,idx] = max(store(:,stress_column_txt));
% c ={idx};
stress{i}=store(:,stress_column_txt);
strain{i} =store(:,strain_column_txt);
end
end
end
title_name=input('Title? ','s')
cc=jet(x);
for i=1:x
figure(1)
plot(strain{i},stress{i});
hold on
legendInfo{i}=[fileName{i}];
end
legend(legendInfo)
xlabel('strain [%]');
ylabel('Stress [MPa]');
grid on;
title(title_name);
  8 commentaires
Walter Roberson
Walter Roberson le 10 Juil 2017
How are you reading in the text files? How are you reading in the csv files?
sivalogan satchithanandamoorthy
did not see your question until now. I do not get notification, if someone ask a question. I only get if for answer. Any way you would have found it by now, answer for the question above since you have answered my question.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Juil 2017
[pathstr, name, ext{i}] = fileparts(pathToFile{i}); %had to add this line to get the file extension
if strcmp(ext{i}, 'txt')
store = importdata(pathToFile{i}, ',', 1); %I am guessing about the delimiter
else
store = importdata(pathToFile{i});
end
  6 commentaires
Walter Roberson
Walter Roberson le 10 Juil 2017
store = importdata(pathToFile{i})
alone should work on those files.
sivalogan satchithanandamoorthy
yea man it does, thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by