Readtable unable to open file Error
Show older comments
Hi all!
I am running a code to get boxplots from different files (00DataProc/Boxplot.mlx). I ran some tests and I could do it in a separate Folder. However, when I went straight to the real Folder I am working with, something in the path (that's my guess) doesn't allow me to use readtable (00DataProc/Imported/).
My files are like the following:

And I want to store them in a specific Folder (00DataProc/BoxPlots/P) like the following:

My code so far is the following:
% Setting up the code: fresh start
clc
clear all
close all
%%% Box Plot
%% The following code perform boxplots for every file allocated in Folder
%Input Folder
folder = '/Users/santiagogomezduenas/OneDrive/00DataProc/'; %Source Path
%%Files in Folder
% Open any file with the extension TXT
f = fullfile(folder,'Precip_Month_Tot_.txt')
list= dir(f);
%Count number of files in Folder
nFile = length(list);
%%Boxplotting Files
% Initialise counter
i = 0
%%Loop for plotting multiple files
for file = list
% Add to the counter
i = i +1
% Open file with set format as Table
data_Table = readtable(file.name,'Format','%f%f%f%f%f%f%f%f%f%f%f%f%f','HeaderLines',13,'Delimiter',';');% Here I get my error
%Transform table to array
data_Array = table2array(data_Table)
%Retrieve from array only Var numbers and not Years
Pure_Data_Array = data_Array(:,[2:13])
%Retrieve File's name
filename = file.name
%Retrieve station's code
Code_Station = extractBetween(filename,'Precip_Month_Tot_','.txt')
Codename = char(Code_Station)
%%Plot Setup
% Plot counter
fig = figure(i)
%Force plot to pop up
set(gcf,'Visible','on')
% Boxplot
boxplot(Pure_Data_Array)
grid on
%Adding Labels
title(Code_Station)
xlabel('Month')
ylabel('Precipitation (mm)')
%%Wiley Art conditions setup
set(gcf,'PaperUnits','centimeters', 'papersize',[10 6],'PaperPosition',[0 0 10 6],'outerposition', [0 0 10 6]);
print('-dpdf','r1000')
saveas(gcf,['/Users/santiagogomezduenas/OneDrive/00DataProc/BoxPlots/P/',Codename,'.pdf'])
end
I'd really appreciate if you could help me understand the error.
Thanks!
1 Comment
Maadhav Akula
on 13 Dec 2019
It would be helpful if you can share the error message and also I have a question regarding the source path, in the code, source path is:
'/Users/santiagogomezduenas/OneDrive/00DataProc/'
whereas, from the image it looks like the source path should have been:
'/Users/santiagogomezduenas/OneDrive/00DataProc/Imported/'
Answers (0)
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!