How can I add path in Matlab to read files csv and excel files from specific folder and read the data?
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Arshey Dhangekar
le 16 Juin 2021
Modifié(e) : Stephen23
le 20 Juin 2021
I want to add path in my script so that it can read and store csv and excel files in struct. I want to add "D:\AMXE132#03\200917\Duty-01\BL" or any path in script to access csv and excel files.
%my path D:\AMXE132#03\200917\Duty-01\BL
Also
I tried import data from csv file but it is detecting var 1 var 2.. Var 3 as header. Row 38 header is getting. How can solve the header reading issue
%Import the options of the csv file
opts=detectImportOptions('WT_ - 10-15.csv');
%Defines the row location of channel variable name
opts.VariableNamesLine = 38;
%Specifies that the data is comma seperated
opts.Delimiter =','; %Specifies that the data is comma seperated
%Read the table
t = readtable('WT_ - 10-15.csv',opts, 'ReadVariableNames', true);
1 commentaire
Réponse acceptée
Walter Roberson
le 16 Juin 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/655500/WT_%20-%2010-15.csv';
t = readtable(filename, 'HeaderLines', 37, 'VariableNamingRule', 'preserve');
t.Properties.VariableNames(1:2)
Your variable names line uses semi-colon as the delimiter, not comman.
vnc = readcell(filename, 'Range', '38:38');
vn = matlab.lang.makeUniqueStrings(regexp(vnc{1}, ';', 'split'))
t = readtable(filename, 'HeaderLines', 38, 'ReadVariableNames', false);
t.Properties.VariableNames = vn;
t(1,:)
Note that Pm-1-Total-WT1 occurs twice, so the second one had to be renamed to Pm-1-Total-WT1_1
6 commentaires
Walter Roberson
le 18 Juin 2021
So only asked how to add path of current folder
There is a long-standing disagreement about how volunteers should respond to questions here on MATLAB Answers. Perhaps you can resolve it for us:
When someone asks a question here, should the volunteers:
[A] Only answer exactly to what the person asks, and if the person obviously asks the wrong question, then answer to what they asked without discussing about what else they might mean. For example, if someone tries to use [] for indexing, instead of showing them how to use () or {} for indexing, tell them they need to open a technical support case to have Mathworks "fix" the "bug" in MATLAB, instead of telling them about () indexing; OR
[B] Answer to the absolute closest to what the person asked that can be achieved in MATLAB, even if it takes dozens of pages of code but what the person probably wanted might be solved in just a few characters. That is, should the volunteers assume that if someone asked to do something a particular way, that the person always has a Good Reason to want to do it that way, and it isn't the business of the volunteers to offer advice? Last week there was an instance in which to solve what the person actually asked would have required programming a Universal Turing Machine in MATLAB and then constructing the program data to meet the particular need... but what the person probably wanted was much easier to deal with; OR
[C] Should the volunteers take advantage of their experience to show the person asking the question what it is that the person really needed, and good practices towards accomplishing that goal?
When the volunteers, many of whom have decades of experience in programming, see someone who obviously does not understand the consequences of what they are asking, should the volunteers "butt out !!!" and give what was asked for, instead of what the volunteers could see was needed ? Or should the volunteers... well, you know, try to actually be helpful ?
.... I ask because the volunteers in this thread have been engaged in [C], trying to figure out what the person asking the question actually needed and advising the asker on good ways to accomplish those goals, but it is starting to feel like the volunteers are being told to do [A], only answer to exactly what was asked.
Walter Roberson
le 19 Juin 2021
That did not answer the question.
Should the volunteers answer only exactly what was asked? Or should the volunteers try to show the person better ways of doing what the volunteers (with their experience) figure that the person actually needs ?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!